Skip to content

Commit 4401c53

Browse files
committed
Initial Commit
1 parent 800d38d commit 4401c53

File tree

6 files changed

+59
-2
lines changed

6 files changed

+59
-2
lines changed

angular/app/components/nav-header/nav-header.component.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
class NavHeaderController {
2-
constructor () {
2+
constructor (ContextService) {
33
'ngInject'
44

5+
ContextService.me()
6+
.then((response) => {
7+
response = response.plain()
8+
this.userData = response.data
9+
})
510
//
611
}
712
}

angular/index.services.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { ContextService } from './services/context.service';
12
import { APIService } from './services/API.service'
23
import { DialogService } from './services/dialog.service'
34
import { ToastService } from './services/toast.service'
45

56
angular.module('app.services')
7+
.service('ContextService', ContextService)
68
.service('API', APIService)
79
.service('DialogService', DialogService)
810
.service('ToastService', ToastService)

angular/run/routes.run.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
export function RoutesRun ($rootScope, $state, $auth, AclService, $timeout) {
1+
export function RoutesRun ($rootScope, $state, $auth, AclService, $timeout, API) {
22
'ngInject'
33

44
AclService.resume()
55

6+
if ($auth.isAuthenticated()) {
7+
let UserData = API.service('me', API.all('users'))
8+
UserData.one().get()
9+
.then((response) => {
10+
$rootScope.me = API.copy(response)
11+
})
12+
}
13+
614
/*eslint-disable */
715
let deregisterationCallback = $rootScope.$on('$stateChangeStart', function (event, toState) {
816
if (toState.data && toState.data.auth) {

angular/services/context.service.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export class ContextService{
2+
constructor($auth, API){
3+
'ngInject';
4+
this.$auth = $auth
5+
this.API = API
6+
}
7+
8+
me() {
9+
let $auth = this.$auth
10+
11+
if ($auth.isAuthenticated()) {
12+
let API = this.API
13+
let UserData = API.service('me', API.all('users'))
14+
15+
return UserData.one().get()
16+
} else {
17+
return null
18+
}
19+
}
20+
}
21+

app/Http/Controllers/UserController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@
1414

1515
class UserController extends Controller
1616
{
17+
/**
18+
* Get user current context
19+
*
20+
* @return JSON
21+
*/
1722
public function getMe()
1823
{
1924
$user = Auth::user();
2025

2126
return response()->success($user);
2227
}
2328

29+
/**
30+
* Update user current context
31+
*
32+
* @return JSON success message
33+
*/
2434
public function putMe(Request $request)
2535
{
2636
$user = Auth::user();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ngDescribe({
2+
name: 'Test ContextService',
3+
modules: 'app',
4+
inject: 'ContextService',
5+
tests: function (deps) {
6+
7+
it('basic test', () => {
8+
//
9+
});
10+
}
11+
});

0 commit comments

Comments
 (0)