· 8 years ago · Feb 06, 2018, 10:48 PM
1//imports/components/dashboard/dashboard.js
2
3import angular from 'angular';
4import angularMeteor from 'angular-meteor';
5import uiRouter from 'angular-ui-router';
6import template from './dashboard.html';
7import './dashboard.css';
8import timetableTeacher from '../timetable/timetable-teacher/timetable-teacher';
9import timetableStudent from '../timetable/timetable-student/timetable-student';
10
11import { Person } from '../../../imports/api/person.js'
12import { Todos, ToDoColln } from '../../api/todo.js';
13import { Calendar } from '../../api/calendar.js';
14import { Announcement } from '../../api/announcements.js';
15import { Cpd } from '../../api/cpd.js';
16
17class Dashboard {
18 constructor($scope, $reactive, $state, $rootScope,$timeout, CurrentPage, timeZone, userAccessService,UserPrivilages, menuHeaderService, mySharedService) {
19 'ngInject';
20 // this.loginAttempt = 0;
21 $reactive(this).attach($scope);
22 let self = this
23 menuHeaderService.exitFromAuthoring()
24 $timeout(function() {
25 CurrentPage.setTitle("Dashboard")
26 })
27 mySharedService.prepForBroadcast("showSidenavIcon");
28
29 let uid = Meteor.userId();
30 localStorage.setItem('FROMSEARCH', "false");
31 if (localStorage.getItem('school_id') != null && localStorage.getItem('school_id') != null) {
32 Session.set("school_id", localStorage.getItem('school_id'))
33 }
34 if (Session.get('role') === 'parent') {
35 $state.go('parentPortalHome')
36 }
37
38 this.subscribe('MytodoList')
39 this.subscribe('getEvents', () => [Session.get('school_id')])
40 this.subscribe('getCpdSessionData', () => [Session.get('school_id')])
41 /*self.subscribe('dashboardPinning', () => [Session.get('school_id')], () => {
42 makeAutorun()
43 })*/
44
45
46 timeZone.timeCheck(function(result) {
47 $scope.todayDate = result
48 Session.set("date", result);
49 })
50
51 $scope.todayDate =new Date()
52
53 let today = $scope.todayDate
54 $scope.minDate = $scope.todayDate
55 if (!$rootScope.online) {
56 today = new Date()
57 $scope.minDate = today
58 }
59 let reqDate = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0)
60 let tomorrow = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0)
61 let reqTime = new Date(today.getTime())
62 tomorrow.setDate(reqDate.getDate() + 1);
63 let yesDate = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0)
64 yesDate.setDate(reqDate.getDate() - 1);
65 this.autorun(() => {
66 // get Todo
67 $scope.upcomingTodo = Todos.find({
68 "taskDate": {
69 $gte: reqDate
70 }
71 },{limit:4}).fetch();
72 //get upcoming Event Count
73 $scope.totalUpcomingEvents = Calendar.find({
74 "user_id":uid,
75 "start": { $gt: reqDate }
76 }).count();
77 //get Today Event Count
78 $scope.totalTodayEvents = Calendar.find({
79 "user_id":uid,
80 "start": { $gt:reqDate, $lt:tomorrow }
81 }).count();
82 //get Announcment Count
83 $scope.announcmentCount = Announcement.find({
84 "users": { "$in": [ uid ] }
85 }).count();
86 $scope.reqSess = Cpd.find({
87 "attendees.user_id": Meteor.userId(),
88 "date_time": { $gt: reqDate.toISOString() }
89 },{limit:5}).fetch()
90 //,{ sort: { date_time:-1 }}
91 //$scope.isTeacherView= true;
92 //$scope.isStudentView= false;
93 $scope.IsfirstPin = Person.find({
94 user_id:Meteor.userId(),
95 dashboardpins: { $exists: true, $not: {$size: 0} }
96 }).count()
97
98 })
99
100
101 $scope.getPinstatus = function(featurid,featuretype) {
102 if($scope.IsfirstPin == 0){
103 //console.log("Oneeee================")
104 let dashPinPrevilege = Person.findOne({
105 user_id:Meteor.userId(),
106 "module_privileges.state":featurid
107 })
108 if (dashPinPrevilege){ return true; }else{ return false; }
109 } else {
110 // console.log("seccc================")
111 let dashPinPrevilege = Person.findOne({
112 user_id:Meteor.userId(),
113 "module_privileges.state":featurid,
114 "dashboardpins":featuretype
115 })
116 if (dashPinPrevilege){ return true; }else{ return false; }
117 }
118 }
119 $scope.getPinfeturestatus = function(featurid) {
120 if($scope.IsfirstPin == 0){
121 let dashPinfeaturPrevilege = Person.findOne({
122 user_id:Meteor.userId(),
123 "feature_privileges.feature_id":featurid
124 })
125 if (dashPinfeaturPrevilege) { return true; }else{ return false; }
126 } else {
127 let dashPinfeaturPrevilege = Person.findOne({
128 user_id:Meteor.userId(),
129 "feature_privileges.feature_id":featurid,
130 "dashboardpins":featurid
131 })
132 if (dashPinfeaturPrevilege) { return true; }else{ return false; }
133 }
134 }
135
136
137 $scope.gotoCPD = function(notification) {
138 $state.go('cpdSections', { viewReq: "new" })
139 }
140 $scope.gotoDsettings = function() {
141 $state.go('dashboardSettings')
142 }
143 // menuHeaderService.exitFromAuthoring()
144
145 //let customerId = [userId]
146 // this.subscribe('getOfflinePracticeTestThemes', () => {
147 // return [] // parameters to be passed to subscribe method
148 // }, () => {
149 // $scope.themeData = []
150 // $scope.themeData = Themes.find({}).fetch()
151 // if (Meteor.isCordova) {
152 // db = window.sqlitePlugin.openDatabase({
153 // name: 'theme.db',
154 // location: 'default'
155 // });
156 // db.transaction(function(tx) {
157 // tx.executeSql('SELECT * FROM DemoTable', [], function(tx, results) {
158 // if (results.rows.length === 0) {
159 // tx.executeSql('CREATE TABLE IF NOT EXISTS DemoTable (_id ,name ,subject_id,curriculum_id,xclass_id ,xindex,count,content_manager_id,book,pdf ,addl,qb,submission_dt)');
160 // _.each($scope.themeData, function(value) {
161 // tx.executeSql('INSERT INTO DemoTable VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)', [value._id, value.name, value.subject_id, value.curriculum_id, value.xclass_id, value.xindex, value.count, value.content_manager_id, value.book, JSON.stringify(value.pdf), JSON.stringify(value.addl), value.qb, value.submission_dt]);
162 // }, function(error) {
163 // }, function() {
164 // });
165 // }
166 // }, function(tx, error) {
167 // });
168 // })
169 // }
170 // })
171 // $scope.$watch(function() {
172 // return $rootScope.online;
173 // }, function() {
174 // let onlineStatus = $rootScope.online;
175 // if (!onlineStatus) {
176 // $scope.db.transaction(function(tx) {
177 // //tx.executeSql('DROP TABLE IF EXISTS my_class');
178 // tx.executeSql('CREATE TABLE IF NOT EXISTS my_class (_id integer primary key, curriculum_id text, session_id text,class_id text, batch_id text,subject_id text,curriculum text, session text ,xclass text , batch text ,subject text)');
179 // });
180 // $scope.fetchClass()
181 // }
182 // }, true);
183 // this.newUser = {
184 // email: '',
185 // password: ''
186 // };
187 // this.error = '';
188 }
189
190 // navigateToTodo() {
191 // $state.go('toDo')
192 // }
193 // navigateToPracticeTest() {
194 // var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
195 // $mdDialog.show({
196 // controller: reportingToPrincipalCtrl,
197 // controllerAs: 'reportingToPrincipalCtrl',
198 // templateUrl: 'client/dynamic-dashboard/choose-my-class.html',
199 // locals: {
200 // reporter: $scope.subjectArr,
201 // },
202 // clickOutsideToClose: true,
203 // fullscreen: useFullScreen
204 // })
205 // .then(function(data) {
206 // if (data) {
207 // Session.setAuth("subjectId", data.subject_id)
208 // //Session.setAuth("subject", obj.name)
209 // //Session.setAuth("class", obj.class)
210 // //Session.setAuth("batch", obj.batch)
211 // Session.setAuth("classId", data.class_id)
212 // //Session.setAuth("role", obj.type)
213 // Session.setAuth("batchId", data.batch_id)
214 // Session.setAuth("sessionId", data.session_id)
215 // Session.setAuth("curriculumId", data.curriculum_id)
216 // $state.go('practiceList')
217 // }
218 // //$scope.status = 'You said the information was "' + answer + '".';
219 // }, function() {
220 // $scope.status = 'You cancelled the dialog.';
221 // });
222 // }
223 // navigateToIBT() {
224 // var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
225 // $mdDialog.show({
226 // controller: reportingToPrincipalCtrl,
227 // controllerAs: 'reportingToPrincipalCtrl',
228 // templateUrl: 'client/dynamic-dashboard/choose-my-class.html',
229 // locals: {
230 // reporter: $scope.subjectArr,
231 // },
232 // clickOutsideToClose: true,
233 // fullscreen: useFullScreen
234 // })
235 // .then(function(data) {
236 // if (data) {
237 // Session.setAuth("subjectId", data.subject_id)
238 // //Session.setAuth("subject", obj.name)
239 // //Session.setAuth("class", obj.class)
240 // //Session.setAuth("batch", obj.batch)
241 // Session.setAuth("classId", data.class_id)
242 // //Session.setAuth("role", obj.type)
243 // Session.setAuth("batchId", data.batch_id)
244 // Session.setAuth("sessionId", data.session_id)
245 // Session.setAuth("curriculumId", data.curriculum_id)
246 // $state.go('ibtComponent')
247 // }
248 // //$scope.status = 'You said the information was "' + answer + '".';
249 // }, function() {
250 // $scope.status = 'You cancelled the dialog.';
251 // });
252 // }
253 // navigateToQuiz() {
254 // var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
255 // $mdDialog.show({
256 // controller: reportingToPrincipalCtrl,
257 // controllerAs: 'reportingToPrincipalCtrl',
258 // templateUrl: 'client/dynamic-dashboard/choose-my-class.html',
259 // locals: {
260 // reporter: $scope.subjectArr,
261 // },
262 // clickOutsideToClose: true,
263 // fullscreen: useFullScreen
264 // })
265 // .then(function(data) {
266 // if (data) {
267 // Session.setAuth("subjectId", data.subject_id)
268 // //Session.setAuth("subject", obj.name)
269 // //Session.setAuth("class", obj.class)
270 // //Session.setAuth("batch", obj.batch)
271 // Session.setAuth("classId", data.class_id)
272 // //Session.setAuth("role", obj.type)
273 // Session.setAuth("batchId", data.batch_id)
274 // Session.setAuth("sessionId", data.session_id)
275 // Session.setAuth("curriculumId", data.curriculum_id)
276 // $state.go('quizList')
277 // }
278 // //$scope.status = 'You said the information was "' + answer + '".';
279 // }, function() {
280 // $scope.status = 'You cancelled the dialog.';
281 // });
282 // }
283 // navigateToAssessment() {
284 // var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
285 // $mdDialog.show({
286 // controller: reportingToPrincipalCtrl,
287 // controllerAs: 'reportingToPrincipalCtrl',
288 // templateUrl: 'client/dynamic-dashboard/choose-my-class.html',
289 // locals: {
290 // reporter: $scope.subjectArr,
291 // },
292 // clickOutsideToClose: true,
293 // fullscreen: useFullScreen
294 // })
295 // .then(function(data) {
296 // if (data) {
297 // Session.setAuth("subjectId", data.subject_id)
298 // //Session.setAuth("subject", obj.name)
299 // //Session.setAuth("class", obj.class)
300 // //Session.setAuth("batch", obj.batch)
301 // Session.setAuth("classId", data.class_id)
302 // //Session.setAuth("role", obj.type)
303 // Session.setAuth("batchId", data.batch_id)
304 // Session.setAuth("sessionId", data.session_id)
305 // Session.setAuth("curriculumId", data.curriculum_id)
306 // $state.go('assessmentList')
307 // }
308 // //$scope.status = 'You said the information was "' + answer + '".';
309 // }, function() {
310 // $scope.status = 'You cancelled the dialog.';
311 // });
312 // }
313 // navigateToAssignment(dest_state) {
314 // var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
315 // $mdDialog.show({
316 // controller: reportingToPrincipalCtrl,
317 // controllerAs: 'reportingToPrincipalCtrl',
318 // templateUrl: 'client/dynamic-dashboard/choose-my-class.html',
319 // locals: {
320 // reporter: $scope.subjectArr,
321 // },
322 // clickOutsideToClose: true,
323 // fullscreen: useFullScreen
324 // })
325 // .then(function(data) {
326 // if (data) {
327 // Session.setAuth("subjectId", data.subject_id)
328 // //Session.setAuth("subject", obj.name)
329 // //Session.setAuth("class", obj.class)
330 // //Session.setAuth("batch", obj.batch)
331 // Session.setAuth("classId", data.class_id)
332 // //Session.setAuth("role", obj.type)
333 // Session.setAuth("batchId", data.batch_id)
334 // Session.setAuth("sessionId", data.session_id)
335 // Session.setAuth("curriculumId", data.curriculum_id)
336 // $state.go(dest_state)
337 // }
338 // //$scope.status = 'You said the information was "' + answer + '".';
339 // }, function() {
340 // $scope.status = 'You cancelled the dialog.';
341 // });
342 // }
343 // fetchClass() {
344 // $scope.db.transaction(function(tx) {
345 // tx.executeSql("select * from my_class;", [], function(tx, res) {
346 // var result = [];
347 // for (var i = 0; i < res.rows.length; i++) {
348 // result.push({
349 // '_id': res.rows.item(i)._id,
350 // 'curriculum_id': res.rows.item(i).curriculum_id,
351 // 'session_id': res.rows.item(i).session_id,
352 // 'class_id': res.rows.item(i).class_id,
353 // 'batch_id': res.rows.item(i).batch_id,
354 // 'subject_id': res.rows.item(i).subject_id,
355 // 'curriculum': res.rows.item(i).curriculum,
356 // 'session': res.rows.item(i).session,
357 // 'xclass': res.rows.item(i).xclass,
358 // 'batch': res.rows.item(i).batch,
359 // 'subject': res.rows.item(i).subject
360 // });
361 // //Session.set("res", result);
362 // }
363 // $scope.subjectArr = result
364 // }, function(e) {
365 // });
366 // });
367 // }
368
369
370}
371
372const name = 'dashboard';
373
374// create a module
375export default angular.module(name, [
376 angularMeteor,
377 uiRouter, 'timetableTeacher', 'timetableStudent'
378 ])
379 .component(name, {
380 templateUrl: template,
381 controllerAs: name,
382 controller: ['$scope', '$reactive', '$state', '$rootScope','$timeout', 'CurrentPage', 'timeZone', 'userAccessService','UserPrivilages', 'menuHeaderService','mySharedService', Dashboard]
383 })
384 .config(['$stateProvider', config]);
385
386function config($stateProvider) {
387 'ngInject';
388 $stateProvider.state('dashboard', {
389 url: '/dashboard',
390 template: '<dashboard></dashboard>',
391 authenticated: true,
392 role: "toAll",
393 resolve: {
394 currentUser: ($q, $state) => {
395 var deferred = $q.defer()
396 if (Meteor.userId()) { //if not logged in, rejects the url
397 } else {
398 return $q.reject('AUTH_REQUIRED');
399 }
400 }
401 }
402 });
403}