Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //imports/components/dashboard/dashboard.js
- import angular from 'angular';
- import angularMeteor from 'angular-meteor';
- import uiRouter from 'angular-ui-router';
- import template from './dashboard.html';
- import './dashboard.css';
- import timetableTeacher from '../timetable/timetable-teacher/timetable-teacher';
- import timetableStudent from '../timetable/timetable-student/timetable-student';
- import { Person } from '../../../imports/api/person.js'
- import { Todos, ToDoColln } from '../../api/todo.js';
- import { Calendar } from '../../api/calendar.js';
- import { Announcement } from '../../api/announcements.js';
- import { Cpd } from '../../api/cpd.js';
- class Dashboard {
- constructor($scope, $reactive, $state, $rootScope,$timeout, CurrentPage, timeZone, userAccessService,UserPrivilages, menuHeaderService, mySharedService) {
- 'ngInject';
- // this.loginAttempt = 0;
- $reactive(this).attach($scope);
- let self = this
- menuHeaderService.exitFromAuthoring()
- $timeout(function() {
- CurrentPage.setTitle("Dashboard")
- })
- mySharedService.prepForBroadcast("showSidenavIcon");
- let uid = Meteor.userId();
- localStorage.setItem('FROMSEARCH', "false");
- if (localStorage.getItem('school_id') != null && localStorage.getItem('school_id') != null) {
- Session.set("school_id", localStorage.getItem('school_id'))
- }
- if (Session.get('role') === 'parent') {
- $state.go('parentPortalHome')
- }
- this.subscribe('MytodoList')
- this.subscribe('getEvents', () => [Session.get('school_id')])
- this.subscribe('getCpdSessionData', () => [Session.get('school_id')])
- /*self.subscribe('dashboardPinning', () => [Session.get('school_id')], () => {
- makeAutorun()
- })*/
- timeZone.timeCheck(function(result) {
- $scope.todayDate = result
- Session.set("date", result);
- })
- $scope.todayDate =new Date()
- let today = $scope.todayDate
- $scope.minDate = $scope.todayDate
- if (!$rootScope.online) {
- today = new Date()
- $scope.minDate = today
- }
- let reqDate = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0)
- let tomorrow = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0)
- let reqTime = new Date(today.getTime())
- tomorrow.setDate(reqDate.getDate() + 1);
- let yesDate = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0)
- yesDate.setDate(reqDate.getDate() - 1);
- this.autorun(() => {
- // get Todo
- $scope.upcomingTodo = Todos.find({
- "taskDate": {
- $gte: reqDate
- }
- },{limit:4}).fetch();
- //get upcoming Event Count
- $scope.totalUpcomingEvents = Calendar.find({
- "user_id":uid,
- "start": { $gt: reqDate }
- }).count();
- //get Today Event Count
- $scope.totalTodayEvents = Calendar.find({
- "user_id":uid,
- "start": { $gt:reqDate, $lt:tomorrow }
- }).count();
- //get Announcment Count
- $scope.announcmentCount = Announcement.find({
- "users": { "$in": [ uid ] }
- }).count();
- $scope.reqSess = Cpd.find({
- "attendees.user_id": Meteor.userId(),
- "date_time": { $gt: reqDate.toISOString() }
- },{limit:5}).fetch()
- //,{ sort: { date_time:-1 }}
- //$scope.isTeacherView= true;
- //$scope.isStudentView= false;
- $scope.IsfirstPin = Person.find({
- user_id:Meteor.userId(),
- dashboardpins: { $exists: true, $not: {$size: 0} }
- }).count()
- })
- $scope.getPinstatus = function(featurid,featuretype) {
- if($scope.IsfirstPin == 0){
- //console.log("Oneeee================")
- let dashPinPrevilege = Person.findOne({
- user_id:Meteor.userId(),
- "module_privileges.state":featurid
- })
- if (dashPinPrevilege){ return true; }else{ return false; }
- } else {
- // console.log("seccc================")
- let dashPinPrevilege = Person.findOne({
- user_id:Meteor.userId(),
- "module_privileges.state":featurid,
- "dashboardpins":featuretype
- })
- if (dashPinPrevilege){ return true; }else{ return false; }
- }
- }
- $scope.getPinfeturestatus = function(featurid) {
- if($scope.IsfirstPin == 0){
- let dashPinfeaturPrevilege = Person.findOne({
- user_id:Meteor.userId(),
- "feature_privileges.feature_id":featurid
- })
- if (dashPinfeaturPrevilege) { return true; }else{ return false; }
- } else {
- let dashPinfeaturPrevilege = Person.findOne({
- user_id:Meteor.userId(),
- "feature_privileges.feature_id":featurid,
- "dashboardpins":featurid
- })
- if (dashPinfeaturPrevilege) { return true; }else{ return false; }
- }
- }
- $scope.gotoCPD = function(notification) {
- $state.go('cpdSections', { viewReq: "new" })
- }
- $scope.gotoDsettings = function() {
- $state.go('dashboardSettings')
- }
- // menuHeaderService.exitFromAuthoring()
- //let customerId = [userId]
- // this.subscribe('getOfflinePracticeTestThemes', () => {
- // return [] // parameters to be passed to subscribe method
- // }, () => {
- // $scope.themeData = []
- // $scope.themeData = Themes.find({}).fetch()
- // if (Meteor.isCordova) {
- // db = window.sqlitePlugin.openDatabase({
- // name: 'theme.db',
- // location: 'default'
- // });
- // db.transaction(function(tx) {
- // tx.executeSql('SELECT * FROM DemoTable', [], function(tx, results) {
- // if (results.rows.length === 0) {
- // 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)');
- // _.each($scope.themeData, function(value) {
- // 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]);
- // }, function(error) {
- // }, function() {
- // });
- // }
- // }, function(tx, error) {
- // });
- // })
- // }
- // })
- // $scope.$watch(function() {
- // return $rootScope.online;
- // }, function() {
- // let onlineStatus = $rootScope.online;
- // if (!onlineStatus) {
- // $scope.db.transaction(function(tx) {
- // //tx.executeSql('DROP TABLE IF EXISTS my_class');
- // 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)');
- // });
- // $scope.fetchClass()
- // }
- // }, true);
- // this.newUser = {
- // email: '',
- // password: ''
- // };
- // this.error = '';
- }
- // navigateToTodo() {
- // $state.go('toDo')
- // }
- // navigateToPracticeTest() {
- // var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
- // $mdDialog.show({
- // controller: reportingToPrincipalCtrl,
- // controllerAs: 'reportingToPrincipalCtrl',
- // templateUrl: 'client/dynamic-dashboard/choose-my-class.html',
- // locals: {
- // reporter: $scope.subjectArr,
- // },
- // clickOutsideToClose: true,
- // fullscreen: useFullScreen
- // })
- // .then(function(data) {
- // if (data) {
- // Session.setAuth("subjectId", data.subject_id)
- // //Session.setAuth("subject", obj.name)
- // //Session.setAuth("class", obj.class)
- // //Session.setAuth("batch", obj.batch)
- // Session.setAuth("classId", data.class_id)
- // //Session.setAuth("role", obj.type)
- // Session.setAuth("batchId", data.batch_id)
- // Session.setAuth("sessionId", data.session_id)
- // Session.setAuth("curriculumId", data.curriculum_id)
- // $state.go('practiceList')
- // }
- // //$scope.status = 'You said the information was "' + answer + '".';
- // }, function() {
- // $scope.status = 'You cancelled the dialog.';
- // });
- // }
- // navigateToIBT() {
- // var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
- // $mdDialog.show({
- // controller: reportingToPrincipalCtrl,
- // controllerAs: 'reportingToPrincipalCtrl',
- // templateUrl: 'client/dynamic-dashboard/choose-my-class.html',
- // locals: {
- // reporter: $scope.subjectArr,
- // },
- // clickOutsideToClose: true,
- // fullscreen: useFullScreen
- // })
- // .then(function(data) {
- // if (data) {
- // Session.setAuth("subjectId", data.subject_id)
- // //Session.setAuth("subject", obj.name)
- // //Session.setAuth("class", obj.class)
- // //Session.setAuth("batch", obj.batch)
- // Session.setAuth("classId", data.class_id)
- // //Session.setAuth("role", obj.type)
- // Session.setAuth("batchId", data.batch_id)
- // Session.setAuth("sessionId", data.session_id)
- // Session.setAuth("curriculumId", data.curriculum_id)
- // $state.go('ibtComponent')
- // }
- // //$scope.status = 'You said the information was "' + answer + '".';
- // }, function() {
- // $scope.status = 'You cancelled the dialog.';
- // });
- // }
- // navigateToQuiz() {
- // var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
- // $mdDialog.show({
- // controller: reportingToPrincipalCtrl,
- // controllerAs: 'reportingToPrincipalCtrl',
- // templateUrl: 'client/dynamic-dashboard/choose-my-class.html',
- // locals: {
- // reporter: $scope.subjectArr,
- // },
- // clickOutsideToClose: true,
- // fullscreen: useFullScreen
- // })
- // .then(function(data) {
- // if (data) {
- // Session.setAuth("subjectId", data.subject_id)
- // //Session.setAuth("subject", obj.name)
- // //Session.setAuth("class", obj.class)
- // //Session.setAuth("batch", obj.batch)
- // Session.setAuth("classId", data.class_id)
- // //Session.setAuth("role", obj.type)
- // Session.setAuth("batchId", data.batch_id)
- // Session.setAuth("sessionId", data.session_id)
- // Session.setAuth("curriculumId", data.curriculum_id)
- // $state.go('quizList')
- // }
- // //$scope.status = 'You said the information was "' + answer + '".';
- // }, function() {
- // $scope.status = 'You cancelled the dialog.';
- // });
- // }
- // navigateToAssessment() {
- // var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
- // $mdDialog.show({
- // controller: reportingToPrincipalCtrl,
- // controllerAs: 'reportingToPrincipalCtrl',
- // templateUrl: 'client/dynamic-dashboard/choose-my-class.html',
- // locals: {
- // reporter: $scope.subjectArr,
- // },
- // clickOutsideToClose: true,
- // fullscreen: useFullScreen
- // })
- // .then(function(data) {
- // if (data) {
- // Session.setAuth("subjectId", data.subject_id)
- // //Session.setAuth("subject", obj.name)
- // //Session.setAuth("class", obj.class)
- // //Session.setAuth("batch", obj.batch)
- // Session.setAuth("classId", data.class_id)
- // //Session.setAuth("role", obj.type)
- // Session.setAuth("batchId", data.batch_id)
- // Session.setAuth("sessionId", data.session_id)
- // Session.setAuth("curriculumId", data.curriculum_id)
- // $state.go('assessmentList')
- // }
- // //$scope.status = 'You said the information was "' + answer + '".';
- // }, function() {
- // $scope.status = 'You cancelled the dialog.';
- // });
- // }
- // navigateToAssignment(dest_state) {
- // var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
- // $mdDialog.show({
- // controller: reportingToPrincipalCtrl,
- // controllerAs: 'reportingToPrincipalCtrl',
- // templateUrl: 'client/dynamic-dashboard/choose-my-class.html',
- // locals: {
- // reporter: $scope.subjectArr,
- // },
- // clickOutsideToClose: true,
- // fullscreen: useFullScreen
- // })
- // .then(function(data) {
- // if (data) {
- // Session.setAuth("subjectId", data.subject_id)
- // //Session.setAuth("subject", obj.name)
- // //Session.setAuth("class", obj.class)
- // //Session.setAuth("batch", obj.batch)
- // Session.setAuth("classId", data.class_id)
- // //Session.setAuth("role", obj.type)
- // Session.setAuth("batchId", data.batch_id)
- // Session.setAuth("sessionId", data.session_id)
- // Session.setAuth("curriculumId", data.curriculum_id)
- // $state.go(dest_state)
- // }
- // //$scope.status = 'You said the information was "' + answer + '".';
- // }, function() {
- // $scope.status = 'You cancelled the dialog.';
- // });
- // }
- // fetchClass() {
- // $scope.db.transaction(function(tx) {
- // tx.executeSql("select * from my_class;", [], function(tx, res) {
- // var result = [];
- // for (var i = 0; i < res.rows.length; i++) {
- // result.push({
- // '_id': res.rows.item(i)._id,
- // 'curriculum_id': res.rows.item(i).curriculum_id,
- // 'session_id': res.rows.item(i).session_id,
- // 'class_id': res.rows.item(i).class_id,
- // 'batch_id': res.rows.item(i).batch_id,
- // 'subject_id': res.rows.item(i).subject_id,
- // 'curriculum': res.rows.item(i).curriculum,
- // 'session': res.rows.item(i).session,
- // 'xclass': res.rows.item(i).xclass,
- // 'batch': res.rows.item(i).batch,
- // 'subject': res.rows.item(i).subject
- // });
- // //Session.set("res", result);
- // }
- // $scope.subjectArr = result
- // }, function(e) {
- // });
- // });
- // }
- }
- const name = 'dashboard';
- // create a module
- export default angular.module(name, [
- angularMeteor,
- uiRouter, 'timetableTeacher', 'timetableStudent'
- ])
- .component(name, {
- templateUrl: template,
- controllerAs: name,
- controller: ['$scope', '$reactive', '$state', '$rootScope','$timeout', 'CurrentPage', 'timeZone', 'userAccessService','UserPrivilages', 'menuHeaderService','mySharedService', Dashboard]
- })
- .config(['$stateProvider', config]);
- function config($stateProvider) {
- 'ngInject';
- $stateProvider.state('dashboard', {
- url: '/dashboard',
- template: '<dashboard></dashboard>',
- authenticated: true,
- role: "toAll",
- resolve: {
- currentUser: ($q, $state) => {
- var deferred = $q.defer()
- if (Meteor.userId()) { //if not logged in, rejects the url
- } else {
- return $q.reject('AUTH_REQUIRED');
- }
- }
- }
- });
- }
Add Comment
Please, Sign In to add comment