Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // client
- DesktopContainer = createContainer(() => {
- incomingTable = function() {
- if (!Meteor.userId()) {
- return false;
- }
- var incoming_objects = _.filter( UserObjects.find({ $and: [{userId:Meteor.userId()},{status:'published'}] }).fetch() || [], function(obj3) {
- return typeof obj3.tableId == 'undefined' || obj3.tableId == null;
- });
- _.each(incoming_objects, function(value, key, obj) {
- var object2 = Mongo.Collection.get(obj[key].type).find({_id:obj[key].objectId}).fetch()[0];
- if (object2) {
- obj[key].title = object2.title;
- obj[key].url = object2.url;
- obj[key].picture = object2.picture;
- }
- obj[key].objectId = obj[key].objectId;
- });
- incoming_table = {
- name: 'Incoming',
- _id:'null',
- items: incoming_objects
- }
- return incoming_table;
- }
- userTables = function() {
- var tableIds = _.pluck(Tables.find({boardId:session.currentBoard.get(),status:'published'}).fetch(),'_id');
- var sharedTables_ = SharedTables.find({userId: Meteor.userId(),boardId:session.currentBoard.get()}).fetch();
- var sharedTableIds = _.pluck(sharedTables_,'tableId');
- var sharedTables = Tables.find({_id: { '$in': sharedTableIds.concat(tableIds) }, status:'published' }).fetch();
- _.each(sharedTables, function(table, key) {
- sharedTables[key].shared = true;
- });
- console.log('sharedTables',sharedTables);
- _.each( sharedTables, function(table, key) {
- var tableObjects = UserObjects.find({tableId:table._id}).fetch();
- _.each(tableObjects, function(obj, index) {
- var object1 = Mongo.Collection.get(tableObjects[index].type).find({_id:tableObjects[index].objectId}).fetch()[0];
- if (object1) {
- tableObjects[index].objectId = object1._id;
- tableObjects[index].title = object1.title;
- tableObjects[index].url = object1.url;
- tableObjects[index].picture = object1.picture;
- tableObjects[index].alarm = object1.alarm;
- }
- });
- sharedTables[key].items = _.sortBy(tableObjects, function(o) { return o.tableIndex; });
- });
- return sharedTables;
- }
- getMyBoards = function() {
- var myBoardIds = _.pluck(Boards.find({userId:Meteor.userId()}).fetch(), '_id');
- var sharedBoardIds = _.pluck(SharedBoards.find({userId:Meteor.userId()}).fetch(), 'boardId');
- var allBoardIds = myBoardIds.concat(sharedBoardIds);
- return Boards.find({_id: { $in: allBoardIds }},{sort:{createdAt:1}}).fetch();
- }
- currentBoardName = function() {
- var board = Boards.find({_id:session.currentBoard.get()}).fetch()[0];
- return typeof board == 'undefined' ? '' : board.name ;
- }
- Meteor.subscribe('sharedTables', Meteor.userId(),{
- onReady: function () {
- //console.log("sharedTables onReady", arguments);
- console.log('sharedTables onReady', Tables.find().fetch() );
- },
- onStop: function () {
- console.log("sharedTables onError", arguments);
- }
- });
- Meteor.subscribe('sharedTablesShared', Meteor.userId(),{
- onReady: function () {
- //console.log("sharedTables onReady", arguments);
- console.log('sharedTablesShared onReady', Tables.find().fetch() );
- },
- onStop: function () {
- console.log("sharedTablesShared onError", arguments);
- }
- });
- var userTablesSub = Meteor.subscribe('userTables',{currentBoard:session.currentBoard.get(),newTables:desktopSession.newTables.get()}, {
- onReady: function () {
- // console.log("userTables onReady", arguments);
- var mainBoardId = Boards.find({userId:Meteor.userId()},{sort:{createdAt:1}}).fetch()[0]._id;
- desktopSession.mainBoardId.set(mainBoardId);
- console.log(mainBoardId);
- if ( (false == Roles.userIsInRole(Meteor.userId(), 'technical-support', 'briefcase')
- && false == Roles.userIsInRole(Meteor.userId(), 'super-admin', 'briefcase'))
- || session.currentBoard.get() == null ) {
- session.currentBoard.set(Boards.find({userId:Meteor.userId()}).fetch()[0]._id)
- }
- },
- onStop: function () {
- console.log("userTables onError", arguments);
- }
- });
- return {
- boards: getMyBoards(),
- tables: userTables(),
- incomingtable: incomingTable(),
- deviceType: deviceType,
- touchDevice: touchDevice,
- desktopSession: desktopSession,
- session: session,
- currentBoardName: currentBoardName(),
- SharedTables: SharedTables.find().fetch()
- };
- }, Desktop);
- // server
- Meteor.publish("sharedTablesShared", function() {
- if (!this.userId) {
- return;
- }
- return SharedTables.find({userId: this.userId});
- });
- Meteor.publish("sharedTables", function() {
- if (!this.userId) {
- return;
- }
- var sharedTableIds = _.pluck(SharedTables.find({userId: this.userId}).fetch(),'tableId');
- var tables = Tables.find({_id: { '$in': sharedTableIds }, status:'published' });
- return tables;
- /*
- var subscription = this;
- var userHandle = SharedTables.find({userId: this.userId}).observe({
- added: function (obj, fields) {
- console.log('ADDED',obj._id);
- subscription.added("sharedtables", obj._id, fields);
- },
- changed: function(obj, fields) {
- // subscription.changed("sharedtables", id, fields);
- },
- removed: function (obj) {
- // subscription.removed("sharedtables", id);
- }
- });
- subscription.ready();
- subscription.onStop(function () {
- userHandle.stop();
- });
- */
- });
- Meteor.publish("userTables", function(data) {
- if (!this.userId) {
- return;
- }
- if (data.currentBoard != null) {
- check(data.currentBoard, String);
- }
- if (!Roles.userIsInRole(this.userId, 'super-admin', 'briefcase')) {
- data.currentBoard = Boards.find({userId:this.userId}).fetch()[0]._id;
- }
- //boards
- var myBoardIds = _.pluck(Boards.find({userId:this.userId}).fetch(), '_id');
- // sharedBoards
- var sharedBoardIds = _.pluck(SharedBoards.find({userId:this.userId}).fetch(), 'boardId');
- var allBoardIds = myBoardIds.concat(sharedBoardIds);
- var allBoards = Boards.find({_id: { $in: allBoardIds } });
- //tables
- var tableIds = _.pluck(Tables.find({ $and: [{userId:this.userId},{boardId: { '$in': allBoardIds } },{status:'published'}] }).fetch(),'_id');
- // new tables
- var newTablesIds = _.pluck(Tables.find({ $and: [{_id: { '$in': data.newTables }},{boardId:data.currentBoard},{status:'published'}] }).fetch(),'_id');
- var sharedTableIds = _.pluck(SharedTables.find({userId: this.userId}).fetch(),'tableId');
- var sharedBoardTableIds = _.pluck(Tables.find({boardId: { $in: sharedBoardIds } }).fetch(),'_id');
- var allTableIds = tableIds.concat(sharedTableIds,newTablesIds,sharedBoardTableIds);
- var sharedObjectIds = _.pluck(UserObjects.find({tableId: { '$in': sharedTableIds } }).fetch(),'objectId');
- var allTables = Tables.find({_id: { '$in': allTableIds },status:'published' });
- var inComingUserObjects = UserObjects.find({tableId: { $exists: false } });
- var userObjects = UserObjects.find({tableId: { '$in': allTableIds }});
- var inComingUserObjectsIds = _.pluck(inComingUserObjects.fetch(),'objectId');
- var userObjectsIds = _.pluck(userObjects.fetch(),'objectId');
- var allUserObjectsIds = userObjectsIds.concat(sharedObjectIds,inComingUserObjectsIds);
- return [
- allBoards,
- allTables,
- userObjects,
- SharedBoards.find({userId:this.userId}),
- Faq.find({_id: { '$in': allUserObjectsIds }}),
- Products.find({_id: { '$in': allUserObjectsIds } }),
- References.find({_id: { '$in': allUserObjectsIds } }),
- News.find({_id: { '$in': allUserObjectsIds } }),
- Contact.find({_id: { '$in': allUserObjectsIds } }),
- Webinars.find({_id: { '$in': allUserObjectsIds } }),
- Custom.find({_id: { '$in': allUserObjectsIds } })
- ];
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement