mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
Updated Lists to pull last viewed list from db
This commit is contained in:
parent
be07ec72bd
commit
3ad8fab67b
5 changed files with 97 additions and 6 deletions
|
|
@ -2,11 +2,13 @@ import { ListItems } from '../../imports/api/listItems.js'
|
||||||
import { Lists } from '../../imports/api/lists.js';
|
import { Lists } from '../../imports/api/lists.js';
|
||||||
import { Products } from '../../imports/api/products.js';
|
import { Products } from '../../imports/api/products.js';
|
||||||
import { M } from '../lib/assets/materialize.js';
|
import { M } from '../lib/assets/materialize.js';
|
||||||
|
import { UserLast } from '../../imports/api/userLast.js';
|
||||||
|
|
||||||
Template.listItemsForm.onCreated(function() {
|
Template.listItemsForm.onCreated(function() {
|
||||||
this.subscribe("myListItems", Session.get("listId"));
|
this.subscribe("myListItems", Session.get("listId"));
|
||||||
this.subscribe("myLists");
|
this.subscribe("myLists");
|
||||||
this.subscribe("myProducts");
|
this.subscribe("myProducts");
|
||||||
|
this.subscribe("userLastView");
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.listItemsForm.onRendered(function() {
|
Template.listItemsForm.onRendered(function() {
|
||||||
|
|
@ -28,9 +30,16 @@ Template.listItemsForm.onRendered(function() {
|
||||||
|
|
||||||
Template.listItemsForm.helpers({
|
Template.listItemsForm.helpers({
|
||||||
selListName: function() {
|
selListName: function() {
|
||||||
let selListId = Session.get("listId");
|
let selListId = "";
|
||||||
|
if (Session.get("listId")) {
|
||||||
|
selListId = Session.get("listId");
|
||||||
|
} else {
|
||||||
|
selListId = UserLast.findOne({ view: "List", userId: Meteor.userId() }).viewId;
|
||||||
|
}
|
||||||
let listInfo = Lists.findOne({ _id: selListId });
|
let listInfo = Lists.findOne({ _id: selListId });
|
||||||
return listInfo.listName;
|
if (listInfo) {
|
||||||
|
return listInfo.listName;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
itemProdName: function() {
|
itemProdName: function() {
|
||||||
return Products.find({});
|
return Products.find({});
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
import { ListItems } from '../../imports/api/listItems.js';
|
import { ListItems } from '../../imports/api/listItems.js';
|
||||||
import { M } from '../lib/assets/materialize.js';
|
import { M } from '../lib/assets/materialize.js';
|
||||||
|
import { UserLast } from '../../imports/api/userLast.js';
|
||||||
|
|
||||||
Template.listItemsTbl.onCreated(function() {
|
Template.listItemsTbl.onCreated(function() {
|
||||||
this.autorun( () => {
|
this.autorun( () => {
|
||||||
this.subscribe("myListItems", Session.get("listId"));
|
this.subscribe("myListItems", Session.get("listId"));
|
||||||
});
|
});
|
||||||
|
this.subscribe("userLastView");
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.listItemsTbl.onRendered(function() {
|
Template.listItemsTbl.onRendered(function() {
|
||||||
|
|
@ -13,6 +15,14 @@ Template.listItemsTbl.onRendered(function() {
|
||||||
|
|
||||||
Session.set("showReceivedItems", false);
|
Session.set("showReceivedItems", false);
|
||||||
Session.set("searchVal", "");
|
Session.set("searchVal", "");
|
||||||
|
|
||||||
|
if (Session.get("listId")) {
|
||||||
|
console.log("got List Id in Session var.");
|
||||||
|
// no action
|
||||||
|
} else {
|
||||||
|
let selListId = UserLast.find({ view: "List" }).listId;
|
||||||
|
Session.set("listId", selListId);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.listItemsTbl.helpers({
|
Template.listItemsTbl.helpers({
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,19 @@ Template.listsTbl.events({
|
||||||
if (sender.localName == "li" || sender.localName == "span") {
|
if (sender.localName == "li" || sender.localName == "span") {
|
||||||
let listId = event.currentTarget.id;
|
let listId = event.currentTarget.id;
|
||||||
if (listId == "addList") {
|
if (listId == "addList") {
|
||||||
// $('#modalList').modal('open');
|
// opens the modal and allows you to add a new List
|
||||||
} else {
|
} else {
|
||||||
// console.log("listId is: " + listId);
|
// console.log("listId is: " + listId);
|
||||||
Session.set("listId", listId);
|
Session.set("listId", listId);
|
||||||
Meteor.setTimeout(function() {
|
Meteor.call('add.userLast', "List", listId, function(err, result) {
|
||||||
FlowRouter.go('/listitems');
|
if (err) {
|
||||||
}, 100);
|
console.log(" ERROR setting user last list id in db: " + err);
|
||||||
|
} else {
|
||||||
|
Meteor.setTimeout(function() {
|
||||||
|
FlowRouter.go('/listitems');
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
57
imports/api/userLast.js
Normal file
57
imports/api/userLast.js
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
import { Meteor } from 'meteor/meteor';
|
||||||
|
import { Mongo } from 'meteor/mongo';
|
||||||
|
import { check } from 'meteor/check';
|
||||||
|
|
||||||
|
export const UserLast = new Mongo.Collection('userLast');
|
||||||
|
|
||||||
|
UserLast.allow({
|
||||||
|
insert: function(userId, doc){
|
||||||
|
// if use id exists, allow insert
|
||||||
|
return !!userId;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Meteor.methods({
|
||||||
|
'add.userLast' (view, viewId) {
|
||||||
|
check(view, String);
|
||||||
|
check(viewId, String);
|
||||||
|
|
||||||
|
if (!this.userId) {
|
||||||
|
throw new Meteor.Error('Not able to change user view last setting. Make sure you are logged in with valid system administrator credentials.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// first let's find out if there's an entry for this user and view, and if so
|
||||||
|
// we'll just edit that entry with updated information
|
||||||
|
let userListInfo = UserLast.findOne({ userId: this.userId, view: view });
|
||||||
|
if (typeof userListInfo != 'undefined' && userListInfo != "" && userListInfo != null) {
|
||||||
|
// entry exists, call the edit function instead
|
||||||
|
Meteor.call('edit.userLast', view, viewId, function(err, result) {
|
||||||
|
if (err) {
|
||||||
|
console.log(" ERROR moving user to edit for last view: " + err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return UserLast.insert({
|
||||||
|
userId: this.userId,
|
||||||
|
view: view,
|
||||||
|
viewId: viewId,
|
||||||
|
dateAdded: Date(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'edit.userLast' (view, viewId) {
|
||||||
|
check(view, String);
|
||||||
|
check(viewId, String);
|
||||||
|
|
||||||
|
if (!this.userId) {
|
||||||
|
throw new Meteor.Error('Not able to change user view last setting. Make sure you are logged in with valid system administrator credentials.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserLast.update({ view: view, userId: this.userId }, {
|
||||||
|
$set: {
|
||||||
|
viewId: viewId,
|
||||||
|
dateLastUpdate: Date(),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -10,6 +10,7 @@ import moment from 'moment';
|
||||||
import { TaskItems } from '../imports/api/tasks.js';
|
import { TaskItems } from '../imports/api/tasks.js';
|
||||||
import { UserConfig } from '../imports/api/userConfig.js';
|
import { UserConfig } from '../imports/api/userConfig.js';
|
||||||
import { MenuProdLinks } from '../imports/api/menuProdLinks.js';
|
import { MenuProdLinks } from '../imports/api/menuProdLinks.js';
|
||||||
|
import { UserLast } from '../imports/api/userLast.js';
|
||||||
|
|
||||||
Meteor.publish("SystemConfig", function() {
|
Meteor.publish("SystemConfig", function() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -31,6 +32,14 @@ Meteor.publish('userList', function() {
|
||||||
return Meteor.users.find({});
|
return Meteor.users.find({});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Meteor.publish("userLastView", function() {
|
||||||
|
try {
|
||||||
|
return UserLast.find({ userId: this.userId });
|
||||||
|
} catch (error) {
|
||||||
|
console.log(" ---- ERROR pulling user last info: " + error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Meteor.publish("storeInfo", function() {
|
Meteor.publish("storeInfo", function() {
|
||||||
try {
|
try {
|
||||||
return Stores.find({});
|
return Stores.find({});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue