import Permissions from '/imports/api/util/Permissions.js';

Meteor.methods({
    'dashboard.get': ({ projectId }) => {
        const projectIds = Roles.getAllGroupsForUser(Meteor.userId(), Permissions.member);

        const projects = Projects.find({
            _id: {
                $in: projectIds
            }
        }, {
            fields: {
                name: 1,
                news: 1,
                vesselModule: 1
            }
        })
        .fetch()
        .map((project) => {
            project.project = project.name;
            delete project.name;
            return project;
        });

        return {
            myProjects: projects,
            myShifts: [{
                _id: 'asdf',
                tag: 'Trolleydienst',
                date: 20180501,
                start: 1000,
                end: 1200
            }, {
                _id: 'asdf2',
                tag: 'Trolleydienst',
                date: 20180501,
                start: 1000,
                end: 1200
            }]
        };
    }
});

@@ -109,24 +109,65 @@
 tId %7D) =%3E %7B%0A
+        const userId = Meteor.userId();%0A%0A
         cons
@@ -207,31 +207,22 @@
 ForUser(
-Meteor.
 userId
-()
 , Permis
@@ -424,24 +424,49 @@
    news: 1,%0A
+                tags: 1,%0A
             
@@ -485,16 +485,99 @@
 dule: 1%0A
+            %7D,%0A            sort: %7B%0A                name: 1,%0A                _id: 1%0A
         
@@ -686,41 +686,8 @@
 me;%0A
-            delete project.name;%0A
     
@@ -731,23 +731,104 @@
         
-return 
+const today = parseInt(moment().format('YYYYDDD'));%0A%0A        const shifts = Shifts.find(
 %7B%0A      
@@ -837,28 +837,66 @@
     
-myP
+p
 roject
-s: projects
+Id: %7B%0A                $in: projectIds%0A            %7D
 ,%0A  
@@ -909,19 +909,14 @@
     
-myShifts
+date
 : 
-%5B
 %7B%0A  
@@ -933,57 +933,169 @@
     
+$gte: today%0A            %7D,%0A            'teams.participants.
 _id
+'
 : 
-'asdf',%0A                tag: 'Trolleydienst'
+userId%0A        %7D, %7B%0A            fields: %7B%0A                projectId: 1,%0A                tagId: 1
 ,%0A  
@@ -1106,39 +1106,32 @@
           date: 
-2018050
 1,%0A             
@@ -1133,35 +1133,32 @@
         start: 1
-000
 ,%0A              
@@ -1157,35 +1157,32 @@
           end: 1
-200
 %0A            %7D, 
@@ -1172,32 +1172,50 @@
 1%0A            %7D,
+%0A            sort:
  %7B%0A             
@@ -1221,146 +1221,877 @@
     
-_id: 'asdf2',%0A                tag: 'Trolleydienst',%0A                date: 20180501,%0A                start: 1000,%0A                end: 1200
+date: 1,%0A                start: 1,%0A                end: 1,%0A                tagId: 1%0A            %7D%0A        %7D)%0A        .fetch()%0A        .map((shift) =%3E %7B%0A            const project = projects.filter((project) =%3E %7B%0A                return project._id == shift.projectId;%0A            %7D)%5B0%5D;%0A%0A            const tag = project.tags.filter((tag) =%3E %7B%0A                return tag._id == shift.tagId;%0A            %7D)%5B0%5D;%0A%0A            shift.tag = tag.name;%0A            shift.date = parseInt(moment(shift.date, 'YYYYDDD').format('YYYYMMDD'));%0A%0A            return shift;%0A        %7D);%0A%0A        return %7B%0A            myProjects: projects.map((project) =%3E %7B%0A                delete project.name;%0A                delete project.tags;%0A                return project;%0A            %7D),%0A            myShifts: shifts.map((shift) =%3E %7B%0A                delete shift.tagId;%0A                return shift;
 %0A   
@@ -2100,17 +2100,17 @@
        %7D
-%5D
+)
 %0A       

replace dummy shifts with actual data