diff --git a/client/src/app/+admin/admin.module.ts b/client/src/app/+admin/admin.module.ts index e4ba8e5b7..853085a83 100644 --- a/client/src/app/+admin/admin.module.ts +++ b/client/src/app/+admin/admin.module.ts @@ -4,7 +4,7 @@ import { AdminComponent } from './admin.component' import { AdminRoutingModule } from './admin-routing.module' import { FriendsComponent, FriendAddComponent, FriendListComponent, FriendService } from './friends' import { RequestSchedulersComponent, RequestSchedulersStatsComponent, RequestSchedulersService } from './request-schedulers' -import { UsersComponent, UserAddComponent, UserListComponent, UserService } from './users' +import { UsersComponent, UserAddComponent, UserUpdateComponent, UserListComponent, UserService } from './users' import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses' import { SharedModule } from '../shared' @@ -26,6 +26,7 @@ import { SharedModule } from '../shared' UsersComponent, UserAddComponent, + UserUpdateComponent, UserListComponent, VideoAbusesComponent, diff --git a/client/src/app/+admin/users/index.ts b/client/src/app/+admin/users/index.ts index cef2c282c..efcd0d9cb 100644 --- a/client/src/app/+admin/users/index.ts +++ b/client/src/app/+admin/users/index.ts @@ -1,5 +1,5 @@ export * from './shared' -export * from './user-add' +export * from './user-edit' export * from './user-list' export * from './users.component' export * from './users.routes' diff --git a/client/src/app/+admin/users/shared/user.service.ts b/client/src/app/+admin/users/shared/user.service.ts index ffd7ba7da..999013bcc 100644 --- a/client/src/app/+admin/users/shared/user.service.ts +++ b/client/src/app/+admin/users/shared/user.service.ts @@ -5,7 +5,7 @@ import 'rxjs/add/operator/map' import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe' import { AuthHttp, RestExtractor, RestDataSource, User } from '../../../shared' -import { UserCreate } from '../../../../../../shared' +import { UserCreate, UserUpdate } from '../../../../../../shared' @Injectable() export class UserService { @@ -23,6 +23,18 @@ export class UserService { .catch(this.restExtractor.handleError) } + updateUser (userId: number, userUpdate: UserUpdate) { + return this.authHttp.put(UserService.BASE_USERS_URL + userId, userUpdate) + .map(this.restExtractor.extractDataBool) + .catch(this.restExtractor.handleError) + } + + getUser (userId: number) { + return this.authHttp.get(UserService.BASE_USERS_URL + userId) + .map(this.restExtractor.extractDataGet) + .catch(this.restExtractor.handleError) + } + getDataSource () { return new RestDataSource(this.authHttp, UserService.BASE_USERS_URL, this.formatDataSource.bind(this)) } diff --git a/client/src/app/+admin/users/user-add/index.ts b/client/src/app/+admin/users/user-add/index.ts deleted file mode 100644 index 3a4654101..000000000 --- a/client/src/app/+admin/users/user-add/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './user-add.component' diff --git a/client/src/app/+admin/users/user-edit/index.ts b/client/src/app/+admin/users/user-edit/index.ts new file mode 100644 index 000000000..edec02fbb --- /dev/null +++ b/client/src/app/+admin/users/user-edit/index.ts @@ -0,0 +1,2 @@ +export * from './user-add.component' +export * from './user-update.component' diff --git a/client/src/app/+admin/users/user-add/user-add.component.ts b/client/src/app/+admin/users/user-edit/user-add.component.ts similarity index 85% rename from client/src/app/+admin/users/user-add/user-add.component.ts rename to client/src/app/+admin/users/user-edit/user-add.component.ts index 91377a933..40f649cff 100644 --- a/client/src/app/+admin/users/user-add/user-add.component.ts +++ b/client/src/app/+admin/users/user-edit/user-add.component.ts @@ -6,20 +6,20 @@ import { NotificationsService } from 'angular2-notifications' import { UserService } from '../shared' import { - FormReactive, USER_USERNAME, USER_EMAIL, USER_PASSWORD, USER_VIDEO_QUOTA } from '../../../shared' import { UserCreate } from '../../../../../../shared' +import { UserEdit } from './user-edit' @Component({ selector: 'my-user-add', - templateUrl: './user-add.component.html' + templateUrl: './user-edit.component.html' }) -export class UserAddComponent extends FormReactive implements OnInit { - error: string = null +export class UserAddComponent extends UserEdit implements OnInit { + error: string form: FormGroup formErrors = { @@ -59,8 +59,8 @@ export class UserAddComponent extends FormReactive implements OnInit { this.buildForm() } - addUser () { - this.error = null + formValidated () { + this.error = undefined const userCreate: UserCreate = this.form.value @@ -76,4 +76,12 @@ export class UserAddComponent extends FormReactive implements OnInit { err => this.error = err.text ) } + + isCreation () { + return true + } + + getFormButtonTitle () { + return 'Add user' + } } diff --git a/client/src/app/+admin/users/user-add/user-add.component.html b/client/src/app/+admin/users/user-edit/user-edit.component.html similarity index 68% rename from client/src/app/+admin/users/user-add/user-add.component.html rename to client/src/app/+admin/users/user-edit/user-edit.component.html index f84d72c7c..0e23cb731 100644 --- a/client/src/app/+admin/users/user-add/user-add.component.html +++ b/client/src/app/+admin/users/user-edit/user-edit.component.html @@ -1,12 +1,13 @@