Skip to content

Commit 5ca8a56

Browse files
committed
refactor(client:admin): Angular 2
1 parent af48248 commit 5ca8a56

File tree

7 files changed

+76
-63
lines changed

7 files changed

+76
-63
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Component } from '@angular/core';
2+
import { UserService } from '../../components/auth/user.service';
3+
4+
@Component({
5+
selector: 'admin',
6+
template: require('./admin.<%=templateExt%>'),
7+
styles: [require('./admin.<%=styleExt%>')],
8+
})
9+
export class AdminComponent {
10+
<%_ if(filters.ts || filters.flow) { -%>
11+
users: Object[];
12+
13+
<%_ } _%>
14+
static parameters = [UserService];
15+
constructor(userService: UserService) {
16+
this.userService = userService;
17+
// Use the user service to fetch all users
18+
this.userService.query().subscribe(users => {
19+
this.users = users;
20+
});
21+
}
22+
23+
delete(user) {
24+
this.userService.remove(user).subscribe(deletedUser => {
25+
this.users.splice(this.users.indexOf(deletedUser), 1);
26+
});
27+
}
28+
}

Diff for: templates/app/client/app/admin(auth)/admin.controller.js

-18
This file was deleted.

Diff for: templates/app/client/app/admin(auth)/admin.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<div class="container">
22
<p>The delete user and user index api routes are restricted to users with the 'admin' role.</p>
33
<ul class="list-group user-list">
4-
<li class="list-group-item" ng-repeat="user in admin.users">
5-
<div class="user-info">
6-
<strong>{{user.name}}</strong><br>
7-
<span class="text-muted">{{user.email}}</span>
8-
</div>
9-
<a ng-click="admin.delete(user)" class="trash"><span class="fa fa-trash fa-2x"></span></a>
4+
<li class="list-group-item" *ngFor="let user of users">
5+
<div class="user-info">
6+
<strong>{{user.name}}</strong><br>
7+
<span class="text-muted">{{user.email}}</span>
8+
</div>
9+
<a (click)="delete(user)" class="trash"><span class="fa fa-trash fa-2x"></span></a>
1010
</li>
1111
</ul>
1212
</div>

Diff for: templates/app/client/app/admin(auth)/admin.module.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
<%_ if(filters.uirouter) { %>
4+
import { UIRouterModule } from 'ui-router-ng2';<% } %>
5+
<%_ if(filters.ngroute) { %>
6+
import { RouterModule, Routes } from '@angular/router';<% } %>
7+
8+
import { AdminComponent } from './admin.component';
9+
10+
<%_ if(filters.ngroute) { -%>
11+
import { ROUTES } from './admin.routes';<% } %>
12+
<%_ if(filters.uirouter) { -%>
13+
import { STATES } from './admin.routes';<% } %>
14+
15+
@NgModule({
16+
imports: [
17+
BrowserModule,
18+
<%_ if(filters.ngroute) { _%>
19+
RouterModule.forChild(ROUTES),<% } %>
20+
<%_ if(filters.uirouter) { _%>
21+
UIRouterModule.forChild({
22+
states: STATES,
23+
}),<% } %>
24+
],
25+
declarations: [
26+
AdminComponent,
27+
],
28+
exports: [
29+
AdminComponent,
30+
],
31+
})
32+
export class AdminModule {}

Diff for: templates/app/client/app/admin(auth)/admin.routes.js

+8-24
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
'use strict';
1+
import { AdminComponent } from './admin.component';
22

3-
<%_ if (filters.ngroute) { _%>
4-
export default function routes($routeProvider) {
5-
'ngInject';
6-
$routeProvider
7-
.when('/admin', {
8-
template: require('./admin.<%= templateExt %>'),
9-
controller: 'AdminController',
10-
controllerAs: 'admin',
11-
authenticate: 'admin'
12-
});
13-
};<% } %>
14-
<%_ if (filters.uirouter) { _%>
15-
export default function routes($stateProvider) {
16-
'ngInject';
17-
$stateProvider
18-
.state('admin', {
19-
url: '/admin',
20-
template: require('./admin.<%= templateExt %>'),
21-
controller: 'AdminController',
22-
controllerAs: 'admin',
23-
authenticate: 'admin'
24-
});
25-
};<% } %>
3+
<%_ if(filters.uirouter) { -%>
4+
export const STATES = [{
5+
name: 'admin',
6+
url: '/admin',
7+
component: AdminComponent,
8+
}];<% } %>
9+
<%_ if(filters.ngroute) { -%><% } %>

Diff for: templates/app/client/app/admin(auth)/index.js

-13
This file was deleted.

Diff for: templates/app/client/app/app.module.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import { AppComponent } from './app.component';
6060
import { MainModule } from './main/main.module';
6161
import { DirectivesModule } from '../components/directives.module';
6262
import { AccountModule } from './account/account.module';
63-
// import { AdminModule } from './admin/admin.module';
63+
import { AdminModule } from './admin/admin.module';
6464

6565
import constants from './app.constants';
6666

@@ -92,7 +92,7 @@ if(constants.env === 'development') {
9292
MainModule,
9393
DirectivesModule,
9494
AccountModule,
95-
// AdminModule,
95+
AdminModule,
9696
],
9797
declarations: [
9898
AppComponent,

0 commit comments

Comments
 (0)