From 4401c53df9d491e66d6fa55d4c8bf8c591feae70 Mon Sep 17 00:00:00 2001 From: alex quiambao Date: Wed, 25 May 2016 16:57:06 +0800 Subject: [PATCH 1/2] Initial Commit --- .../nav-header/nav-header.component.js | 7 ++++++- angular/index.services.js | 2 ++ angular/run/routes.run.js | 10 ++++++++- angular/services/context.service.js | 21 +++++++++++++++++++ app/Http/Controllers/UserController.php | 10 +++++++++ .../angular/services/context.service.spec.js | 11 ++++++++++ 6 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 angular/services/context.service.js create mode 100644 tests/angular/services/context.service.spec.js diff --git a/angular/app/components/nav-header/nav-header.component.js b/angular/app/components/nav-header/nav-header.component.js index e528496..de05ae2 100644 --- a/angular/app/components/nav-header/nav-header.component.js +++ b/angular/app/components/nav-header/nav-header.component.js @@ -1,7 +1,12 @@ class NavHeaderController { - constructor () { + constructor (ContextService) { 'ngInject' + ContextService.me() + .then((response) => { + response = response.plain() + this.userData = response.data + }) // } } diff --git a/angular/index.services.js b/angular/index.services.js index fc70918..9133501 100644 --- a/angular/index.services.js +++ b/angular/index.services.js @@ -1,8 +1,10 @@ +import { ContextService } from './services/context.service'; import { APIService } from './services/API.service' import { DialogService } from './services/dialog.service' import { ToastService } from './services/toast.service' angular.module('app.services') + .service('ContextService', ContextService) .service('API', APIService) .service('DialogService', DialogService) .service('ToastService', ToastService) diff --git a/angular/run/routes.run.js b/angular/run/routes.run.js index 12d32c4..4b05818 100644 --- a/angular/run/routes.run.js +++ b/angular/run/routes.run.js @@ -1,8 +1,16 @@ -export function RoutesRun ($rootScope, $state, $auth, AclService, $timeout) { +export function RoutesRun ($rootScope, $state, $auth, AclService, $timeout, API) { 'ngInject' AclService.resume() + if ($auth.isAuthenticated()) { + let UserData = API.service('me', API.all('users')) + UserData.one().get() + .then((response) => { + $rootScope.me = API.copy(response) + }) + } + /*eslint-disable */ let deregisterationCallback = $rootScope.$on('$stateChangeStart', function (event, toState) { if (toState.data && toState.data.auth) { diff --git a/angular/services/context.service.js b/angular/services/context.service.js new file mode 100644 index 0000000..85461bc --- /dev/null +++ b/angular/services/context.service.js @@ -0,0 +1,21 @@ +export class ContextService{ + constructor($auth, API){ + 'ngInject'; + this.$auth = $auth + this.API = API + } + + me() { + let $auth = this.$auth + + if ($auth.isAuthenticated()) { + let API = this.API + let UserData = API.service('me', API.all('users')) + + return UserData.one().get() + } else { + return null + } + } +} + diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index c3a4df1..2af3bd1 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -14,6 +14,11 @@ class UserController extends Controller { + /** + * Get user current context + * + * @return JSON + */ public function getMe() { $user = Auth::user(); @@ -21,6 +26,11 @@ public function getMe() return response()->success($user); } + /** + * Update user current context + * + * @return JSON success message + */ public function putMe(Request $request) { $user = Auth::user(); diff --git a/tests/angular/services/context.service.spec.js b/tests/angular/services/context.service.spec.js new file mode 100644 index 0000000..3d53950 --- /dev/null +++ b/tests/angular/services/context.service.spec.js @@ -0,0 +1,11 @@ +ngDescribe({ + name: 'Test ContextService', + modules: 'app', + inject: 'ContextService', + tests: function (deps) { + + it('basic test', () => { + // + }); + } +}); From e8996548ef9e1c60109f03aed56698b59fdca0d8 Mon Sep 17 00:00:00 2001 From: alex quiambao Date: Thu, 26 May 2016 13:44:45 +0800 Subject: [PATCH 2/2] Added user current context --- .../login-form/login-form.component.js | 4 +- .../nav-header/nav-header.component.html | 11 +++--- .../nav-header/nav-header.component.js | 15 ++++---- .../nav-sidebar/nav-sidebar.component.html | 4 +- .../nav-sidebar/nav-sidebar.component.js | 7 +++- angular/config/routes.config.js | 3 +- angular/filters/date_millis.filter.js | 7 ++++ angular/index.filters.js | 4 +- angular/index.services.js | 2 +- angular/run/routes.run.js | 24 ++++++------ angular/services/context.service.js | 38 +++++++++++-------- app/Http/Controllers/UserController.php | 4 +- .../angular/services/context.service.spec.js | 19 +++++----- 13 files changed, 83 insertions(+), 59 deletions(-) create mode 100644 angular/filters/date_millis.filter.js diff --git a/angular/app/components/login-form/login-form.component.js b/angular/app/components/login-form/login-form.component.js index 3b410bb..e5ed517 100644 --- a/angular/app/components/login-form/login-form.component.js +++ b/angular/app/components/login-form/login-form.component.js @@ -1,7 +1,9 @@ class LoginFormController { - constructor ($auth, $state, $stateParams, API, AclService) { + constructor ($rootScope, $auth, $state, $stateParams, API, AclService) { 'ngInject' + delete $rootScope.me + this.$auth = $auth this.$state = $state this.$stateParams = $stateParams diff --git a/angular/app/components/nav-header/nav-header.component.html b/angular/app/components/nav-header/nav-header.component.html index 5d8183b..2becde0 100644 --- a/angular/app/components/nav-header/nav-header.component.html +++ b/angular/app/components/nav-header/nav-header.component.html @@ -212,17 +212,16 @@