]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Client: better confirm box for a beautiful world
authorChocobozzz <florian.bigard@gmail.com>
Fri, 27 Jan 2017 15:54:44 +0000 (16:54 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 27 Jan 2017 15:59:56 +0000 (16:59 +0100)
12 files changed:
client/src/app/+admin/friends/friend-add/friend-add.component.ts
client/src/app/+admin/friends/friend-list/friend-list.component.ts
client/src/app/+admin/users/user-list/user-list.component.ts
client/src/app/app.component.html
client/src/app/core/confirm/confirm.component.html [new file with mode: 0644]
client/src/app/core/confirm/confirm.component.ts [new file with mode: 0644]
client/src/app/core/confirm/confirm.service.ts [new file with mode: 0644]
client/src/app/core/confirm/index.ts [new file with mode: 0644]
client/src/app/core/core.module.ts
client/src/app/core/index.ts
client/src/app/videos/video-list/video-miniature.component.ts
client/src/app/videos/video-watch/video-report.component.ts

index a271970ae70c7e60a20963f4023911ab924637bd..12c46e5cd6fbcae63532c72108ed5c51592d4eb8 100644 (file)
@@ -4,6 +4,7 @@ import { Router } from '@angular/router';
 
 import { NotificationsService } from 'angular2-notifications';
 
+import { ConfirmService } from '../../../core';
 import { validateHost } from '../../../shared';
 import { FriendService } from '../shared';
 
@@ -20,6 +21,7 @@ export class FriendAddComponent implements OnInit {
   constructor(
     private router: Router,
     private notificationsService: NotificationsService,
+    private confirmService: ConfirmService,
     private friendService: FriendService
   ) {}
 
@@ -84,16 +86,20 @@ export class FriendAddComponent implements OnInit {
       return;
     }
 
-    const confirmMessage = 'Are you sure to make friends with:\n - ' + notEmptyHosts.join('\n - ');
-    if (!confirm(confirmMessage)) return;
+    const confirmMessage = 'Are you sure to make friends with:<br /> - ' + notEmptyHosts.join('<br /> - ');
+    this.confirmService.confirm(confirmMessage, 'Make friends').subscribe(
+      res => {
+        if (res === false) return;
 
-    this.friendService.makeFriends(notEmptyHosts).subscribe(
-      status => {
-        this.notificationsService.success('Sucess', 'Make friends request sent!');
-        this.router.navigate([ '/admin/friends/list' ]);
-      },
+        this.friendService.makeFriends(notEmptyHosts).subscribe(
+          status => {
+            this.notificationsService.success('Sucess', 'Make friends request sent!');
+            this.router.navigate([ '/admin/friends/list' ]);
+          },
 
-      err => this.notificationsService.error('Error', err.text)
+          err => this.notificationsService.error('Error', err.text)
+        );
+      }
     );
   }
 
index 700ea7a69fa5175d8e6c425b32630d1363192a68..175ad9cba8938cf489d9d9188462958a8f358c4a 100644 (file)
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
 
 import { NotificationsService } from 'angular2-notifications';
 
+import { ConfirmService } from '../../../core';
 import { Friend, FriendService } from '../shared';
 
 @Component({
@@ -14,6 +15,7 @@ export class FriendListComponent implements OnInit {
 
   constructor(
     private notificationsService: NotificationsService,
+    private confirmService: ConfirmService,
     private friendService: FriendService
   ) {  }
 
@@ -22,16 +24,21 @@ export class FriendListComponent implements OnInit {
   }
 
   quitFriends() {
-    if (!confirm('Are you sure?')) return;
+    const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.';
+    this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe(
+      res => {
+        if (res === false) return;
 
-    this.friendService.quitFriends().subscribe(
-      status => {
-        this.notificationsService.success('Sucess', 'Friends left!');
+        this.friendService.quitFriends().subscribe(
+          status => {
+            this.notificationsService.success('Sucess', 'Friends left!');
 
-        this.getFriends();
-      },
+            this.getFriends();
+          },
 
-      err => this.notificationsService.error('Error', err.text)
+          err => this.notificationsService.error('Error', err.text)
+        );
+      }
     );
   }
 
index ca08ed3050ea41752b54111136ff584993d0441e..baefb7064ce60fa30d99cbce4e06325ed7551006 100644 (file)
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
 
 import { NotificationsService } from 'angular2-notifications';
 
+import { ConfirmService } from '../../../core';
 import { User } from '../../../shared';
 import { UserService } from '../shared';
 
@@ -16,6 +17,7 @@ export class UserListComponent implements OnInit {
 
   constructor(
     private notificationsService: NotificationsService,
+    private confirmService: ConfirmService,
     private userService: UserService
   ) {}
 
@@ -36,15 +38,19 @@ export class UserListComponent implements OnInit {
 
 
   removeUser(user: User) {
-    if (confirm('Are you sure?')) {
-      this.userService.removeUser(user).subscribe(
-        () => {
-          this.notificationsService.success('Success', `User ${user.username} deleted.`);
-          this.getUsers();
-        },
-
-        err => this.notificationsService.error('Error', err.text)
-      );
-    }
+    this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe(
+      res => {
+        if (res === false) return;
+
+        this.userService.removeUser(user).subscribe(
+          () => {
+            this.notificationsService.success('Success', `User ${user.username} deleted.`);
+            this.getUsers();
+          },
+
+          err => this.notificationsService.error('Error', err.text)
+        );
+      }
+    );
   }
 }
index 95a02583216267a7a4569fbe222a1f8b2550224c..9f2661e12fea19f85a1c61bfde1f12b2f1a05fec 100644 (file)
@@ -23,6 +23,7 @@
   </div>
 
   <simple-notifications [options]="notificationOptions"></simple-notifications>
+  <my-confirm></my-confirm>
 
   <footer>
     PeerTube, CopyLeft 2015-2016
diff --git a/client/src/app/core/confirm/confirm.component.html b/client/src/app/core/confirm/confirm.component.html
new file mode 100644 (file)
index 0000000..3052526
--- /dev/null
@@ -0,0 +1,20 @@
+<div bsModal #confirmModal="bs-modal" class="modal" tabindex="-1" role="dialog">
+  <div class="modal-dialog">
+    <div class="modal-content">
+
+      <div class="modal-header">
+        <button type="button" class="close" aria-label="Close" (click)="abort()">
+          <span aria-hidden="true">&times;</span>
+        </button>
+        <h4 class="modal-title">{{ title }}</h4>
+      </div>
+
+      <div class="modal-body" [innerHtml]="message"></div>
+
+      <div class="modal-footer">
+        <button type="button" class="btn btn-default" data-dismiss="modal" (click)="abort()">Annuler</button>
+        <button type="button" class="btn btn-primary" (click)="confirm()">Valider</button>
+      </div>
+    </div>
+  </div>
+</div>
diff --git a/client/src/app/core/confirm/confirm.component.ts b/client/src/app/core/confirm/confirm.component.ts
new file mode 100644 (file)
index 0000000..14b4ef3
--- /dev/null
@@ -0,0 +1,61 @@
+import { Component, HostListener, OnInit, ViewChild } from '@angular/core';
+
+import { ModalDirective } from 'ng2-bootstrap/modal';
+
+import { ConfirmService } from './confirm.service';
+
+export interface ConfigChangedEvent {
+  columns: { [id: string]: { isDisplayed: boolean }; };
+  config: { resultsPerPage: number };
+}
+
+@Component({
+  selector: 'my-confirm',
+  templateUrl: './confirm.component.html'
+})
+export class ConfirmComponent implements OnInit {
+  @ViewChild('confirmModal') confirmModal: ModalDirective;
+
+  title = '';
+  message = '';
+
+  constructor (private confirmService: ConfirmService) {
+    // Empty
+  }
+
+  ngOnInit() {
+    this.confirmModal.config = {
+      backdrop: 'static',
+      keyboard: false
+    };
+
+    this.confirmService.showConfirm.subscribe(
+      ({ title, message }) => {
+        this.title = title;
+        this.message = message;
+
+        this.showModal();
+      }
+    );
+  }
+
+  @HostListener('keydown.enter')
+  confirm() {
+    this.confirmService.confirmResponse.next(true);
+    this.hideModal();
+  }
+
+  @HostListener('keydown.esc')
+  abort() {
+    this.confirmService.confirmResponse.next(false);
+    this.hideModal();
+  }
+
+  showModal() {
+    this.confirmModal.show();
+  }
+
+  hideModal() {
+    this.confirmModal.hide();
+  }
+}
diff --git a/client/src/app/core/confirm/confirm.service.ts b/client/src/app/core/confirm/confirm.service.ts
new file mode 100644 (file)
index 0000000..b979697
--- /dev/null
@@ -0,0 +1,15 @@
+import { Injectable } from '@angular/core';
+import { Subject } from 'rxjs/Subject';
+import 'rxjs/add/operator/first';
+
+@Injectable()
+export class ConfirmService {
+  showConfirm = new Subject<{ title, message }>();
+  confirmResponse = new Subject<boolean>();
+
+  confirm(message: string = '', title: string = '') {
+    this.showConfirm.next({ title, message });
+
+    return this.confirmResponse.asObservable().first();
+  }
+}
diff --git a/client/src/app/core/confirm/index.ts b/client/src/app/core/confirm/index.ts
new file mode 100644 (file)
index 0000000..789e7e5
--- /dev/null
@@ -0,0 +1,2 @@
+export * from './confirm.component';
+export * from './confirm.service';
index 48fec2d439a0bed607f69cc09077579f237e7d45..f02304647eea308dd5d825aa1ee7d86f7c5ac729 100644 (file)
@@ -4,8 +4,10 @@ import { HttpModule } from '@angular/http';
 import { RouterModule } from '@angular/router';
 
 import { SimpleNotificationsModule } from 'angular2-notifications';
+import { ModalModule } from 'ng2-bootstrap/modal';
 
 import { AuthService } from './auth';
+import { ConfirmComponent, ConfirmService } from './confirm';
 import { MenuComponent, MenuAdminComponent } from './menu';
 import { throwIfAlreadyLoaded } from './module-import-guard';
 
@@ -15,19 +17,28 @@ import { throwIfAlreadyLoaded } from './module-import-guard';
     HttpModule,
     RouterModule,
 
+    ModalModule,
     SimpleNotificationsModule
   ],
+
   declarations: [
+    ConfirmComponent,
     MenuComponent,
     MenuAdminComponent
   ],
+
   exports: [
     SimpleNotificationsModule,
 
+    ConfirmComponent,
     MenuComponent,
     MenuAdminComponent
   ],
-  providers: [ AuthService ]
+
+  providers: [
+    AuthService,
+    ConfirmService
+  ]
 })
 export class CoreModule {
    constructor( @Optional() @SkipSelf() parentModule: CoreModule) {
index fa951b215394bbab0a0574b0017bac04b8e50218..9b4dd1999bb69de00ea3f4758418eca056a1b305 100644 (file)
@@ -1,2 +1,4 @@
 export * from './auth';
+export * from './confirm';
+export * from './menu';
 export * from './core.module'
index ca4afc451bb7c2fc858b8c82a546b57fc718f4c4..ba47155972a08d2b24cce7290b488b9da3a2342d 100644 (file)
@@ -2,6 +2,7 @@ import { Component, Input, Output, EventEmitter } from '@angular/core';
 
 import { NotificationsService } from 'angular2-notifications';
 
+import { ConfirmService } from '../../core';
 import { SortField, Video, VideoService } from '../shared';
 import { User } from '../../shared';
 
@@ -22,6 +23,7 @@ export class VideoMiniatureComponent {
 
   constructor(
     private notificationsService: NotificationsService,
+    private confirmService: ConfirmService,
     private videoService: VideoService
   ) {}
 
@@ -38,12 +40,16 @@ export class VideoMiniatureComponent {
   }
 
   removeVideo(id: string) {
-    if (confirm('Do you really want to remove this video?')) {
-      this.videoService.removeVideo(id).subscribe(
-        status => this.removed.emit(true),
+    this.confirmService.confirm('Do you really want to delete this video?', 'Delete').subscribe(
+      res => {
+        if (res === false) return;
 
-        error => this.notificationsService.error('Error', error.text)
-      );
-    }
+        this.videoService.removeVideo(id).subscribe(
+          status => this.removed.emit(true),
+
+          error => this.notificationsService.error('Error', error.text)
+        );
+      }
+    );
   }
 }
index 19a7af1482c3c3ff9f429450004c36c13bf7b756..7906fdb5c429c3da6cc4b10c5dfb583cc2651b38 100644 (file)
@@ -57,13 +57,13 @@ export class VideoReportComponent extends FormReactive implements OnInit {
     const reason = this.form.value['reason']
 
     this.videoAbuseService.reportVideo(this.video.id, reason)
-                     .subscribe(
-                       () => {
-                         this.notificationsService.success('Success', 'Video reported.');
-                         this.hide();
-                       },
+                          .subscribe(
+                            () => {
+                              this.notificationsService.success('Success', 'Video reported.');
+                              this.hide();
+                            },
 
-                       err => this.notificationsService.error('Error', err.text);
-                      )
+                            err => this.notificationsService.error('Error', err.text)
+                           );
   }
 }