diff --git a/README.md b/README.md index 51f86b8..8b10a05 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ Created using [AngularJS Seed](https://github.com/angular/angular-seed). This is the open source version of my original project called Ujian Berbasis Komputer - Teka-teki Silang (Computer Based Test - Crossword). So this closed source project does exist since 13 September 2016. The open source version initialized on 12 January 2017. Every suspicious commercials activity of this project happened before 12 January 2017 are marked as illegal. -The differences from closed source version are: +The differences from the closed source version are: + 1. Variable names translated from Indonesian to English 1. Model & code adjustments either on API Server & Mobile Application packages 1. Using ES6 & ES7 javascript language @@ -157,4 +158,24 @@ Then, you can start serving your production ready package by using this command: After that, you can visit http://localhost:2796 on your browser to start using this application on production mode. -Note that you can change the configured production server port (2796) from [package.json](package.json) file. \ No newline at end of file +Note that you can change the configured production server port (2796) from [package.json](package.json) file. + +### Default Accounts + +``` +Admin +email: admin@mailinator.com +pass: asdqwe123 +``` + +``` +Guru +email: guru@mailinator.com +pass: asdqwe123 +``` + +``` +Participant +email: participant@mailinator.com +pass: asdqwe123 +``` \ No newline at end of file diff --git a/app/app-acl.js b/app/app-acl.js index bf5cb2f..3eaab95 100644 --- a/app/app-acl.js +++ b/app/app-acl.js @@ -5,7 +5,7 @@ angular.module('app') '$location', 'AclService', 'Authentication', - async( + ( $rootScope, $state, $location, @@ -67,27 +67,27 @@ angular.module('app') }; AclService.setAbilities(aclData); - AclService.attachRole('guest'); $rootScope.$on('$stateChangeStart', function (e, to) { - if (!AclService.can(to.name)) { - e.preventDefault(); - $state.go('app'); - } + $rootScope.stateTransition = to; }); - $rootScope.$on('$stateChangeSuccess', function (e, to) { - if (!to.name || to.name === 'app') { - if (AclService.hasRole('$authenticated')) { - if ($state.current.name !== 'app.dashboard') $state.go('app.dashboard'); - } else { - if ($state.current.name !== 'app.login') $state.go('app.login'); - } - } + $rootScope.$on('$stateChangeSuccess', function () { + delete $rootScope.stateTransition; }); - await Authentication.authenticationCheck(); + Authentication.authenticationCheck().then(() => { + $rootScope.$on('$stateChangeStart', function (e, to) { + if (to.name && !AclService.can(to.name)) { + e.preventDefault(); + $state.go('app'); + } + }); + $rootScope.$on('$stateChangeSuccess', () => { + Authentication.redirector(); + }); + }); $rootScope.acl = AclService; }, diff --git a/app/app-formly.js b/app/app-formly.js index 522a21d..09350ac 100644 --- a/app/app-formly.js +++ b/app/app-formly.js @@ -177,6 +177,8 @@ angular.module('app') $translate, formlyValidationMessages ) => { - formlyValidationMessages.addStringMessage('required', $translate.instant('error.validation.required')); + $translate('error.validation.required').then((message) => { + formlyValidationMessages.addStringMessage('required', message); + }); } ]); \ No newline at end of file diff --git a/app/app-run.js b/app/app-run.js index 12917c1..8cdf9b4 100644 --- a/app/app-run.js +++ b/app/app-run.js @@ -5,23 +5,28 @@ angular.module('app') '$mdToast', '$translate', '$window', + '$timeout', 'Utils', 'AclService', 'Menu', - async( + ( $rootScope, $state, $mdToast, $translate, $window, + $timeout, Utils, AclService, Menu ) => { $rootScope.config = { - menuTitle: await $translate('menu.main'), + menuTitle: '', pageTitle: '', }; + $translate('menu.main').then((message) => { + $rootScope.config.menuTitle = message; + }); $rootScope.excludeMenu = ['app.login', 'app.test.start']; $rootScope.excludeHeader = ['app.login']; @@ -96,14 +101,33 @@ angular.module('app') }); $rootScope.timeLabel = { - hour: await $translate('time.hour'), - minute: await $translate('time.minute'), - second: await $translate('time.second'), + hour: '', + minute: '', + second: '', }; + $translate('time.hour').then((message) => { + $rootScope.timeLabel.hour = message; + }); + $translate('time.minute').then((message) => { + $rootScope.timeLabel.minute = message; + }); + $translate('time.second').then((message) => { + $rootScope.timeLabel.second = message; + }); + $rootScope.paginationLabel = { - page: await $translate('pagination.page'), - rowsPerPage: await $translate('pagination.rowsPerPage'), - of: await $translate('pagination.of'), + page: '', + rowsPerPage: '', + of: '', }; + $translate('pagination.page').then((message) => { + $rootScope.paginationLabel.page = message; + }); + $translate('pagination.rowsPerPage').then((message) => { + $rootScope.paginationLabel.rowsPerPage = message; + }); + $translate('pagination.of').then((message) => { + $rootScope.paginationLabel.of = message; + }); }, ]); \ No newline at end of file diff --git a/app/components/controllers/package/schedule/list.js b/app/components/controllers/package/schedule/list.js index 44e4277..21bee30 100644 --- a/app/components/controllers/package/schedule/list.js +++ b/app/components/controllers/package/schedule/list.js @@ -222,17 +222,18 @@ angular.module('app') vmDialog.submit = async() => { let schedule = angular.copy(vmDialog.schedule); - let startTime = moment(vmDialog.schedule.startTime, 'HH:mm'); - vmDialog.schedule.start = - moment(new Date(vmDialog.schedule.start)) + let startTime = moment(schedule.startTime, 'HH:mm'); + schedule.start = moment(new Date(schedule.start)) .hour(startTime.hour()) - .minute(startTime.minute()); + .minute(startTime.minute()).toISOString(); - let endTime = moment(vmDialog.schedule.endTime, 'HH:mm'); - vmDialog.schedule.end = - moment(new Date(vmDialog.schedule.end)) + let endTime = moment(schedule.endTime, 'HH:mm'); + schedule.end = moment(new Date(schedule.end)) .hour(endTime.hour()) - .minute(endTime.minute()); + .minute(endTime.minute()).toISOString(); + + delete schedule.startTime; + delete schedule.endTime; if (!vmDialog.isEdit) { await PackageSchedule.create(_.extend(schedule, { @@ -241,7 +242,7 @@ angular.module('app') } else { await PackageSchedule.update({ where: { - id: vmDialog.schedule.id, + id: schedule.id, }, }, schedule).$promise; } diff --git a/app/components/services/authentication.js b/app/components/services/authentication.js index 43dd2dc..14d3e94 100644 --- a/app/components/services/authentication.js +++ b/app/components/services/authentication.js @@ -2,20 +2,38 @@ angular.module('app') .factory('Authentication', [ '$rootScope', '$state', - '$http', + '$location', 'AclService', 'Menu', 'Person', ( $rootScope, $state, - $http, + $location, AclService, Menu, Person ) => { const service = {}; + service.redirector = () => { + if ($location.path() === '/') { + if (AclService.hasRole('$authenticated')) { + $state.go('app.dashboard'); + } else { + $state.go('app.login'); + } + } else if (_.has($rootScope, 'stateTransition.name') && !AclService.can($rootScope.stateTransition.name)) { + $state.go('app'); + } + } + + service.authorize = (state) => { + if (state.name && !AclService.can(state.name)) { + $state.go('app'); + } + } + service.authenticationCheck = async() => { if (!localStorage.getItem('$LoopBack$accessTokenId')) { return false; @@ -28,7 +46,7 @@ angular.module('app') AclService.attachRole(role); } $rootScope.menus = Menu.menus(); - $state.go('app.dashboard'); + service.redirector(); } catch (e) { await service.logout(); return false; @@ -39,6 +57,7 @@ angular.module('app') if ((model.email || model.username) && model.password) { await Person.login(model).$promise; await service.authenticationCheck(); + $state.go('app'); } }; diff --git a/package.json b/package.json index f33e5c1..70b3f8f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cbt-crossword-web", - "version": "1.0.0-alpha1", + "version": "1.0.0-alpha2", "repository": { "type": "git", "url": "https://github.com/labibramadhan/cbt-crossword-web.git"