From f94bd07cb28bcde352a6fafa7ccabf28e6c8acff Mon Sep 17 00:00:00 2001 From: Lukas Haase <lukas.haase@mni.thm.de> Date: Thu, 29 Oct 2020 11:56:16 +0100 Subject: [PATCH] add shortid to service --- .../room-create/room-create.component.html | 17 +++++++---------- .../room-create/room-create.component.ts | 9 ++++++--- .../shared/header/header.component.html | 3 ++- src/app/models/room.ts | 2 +- src/app/services/http/room.service.ts | 9 +++++++-- src/assets/i18n/home/de.json | 5 ++++- src/assets/i18n/home/en.json | 5 ++++- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/app/components/shared/_dialogs/room-create/room-create.component.html b/src/app/components/shared/_dialogs/room-create/room-create.component.html index 451bec7fd..85dd6ad67 100644 --- a/src/app/components/shared/_dialogs/room-create/room-create.component.html +++ b/src/app/components/shared/_dialogs/room-create/room-create.component.html @@ -10,19 +10,19 @@ #roomName class="input-block" type="text" - maxlength="20" + maxlength="100" [(ngModel)]="longName" name="roomName" aria-labelledby="room-name-input"/> <mat-placeholder class="placeholder">{{ 'session.session-name' | translate }}</mat-placeholder> <mat-hint align="end" class="count" - *ngIf="!emptyInputs"><span aria-hidden="true">{{roomName.value.length}} / 20</span></mat-hint> + *ngIf="!emptyInputs"><span aria-hidden="true">{{roomName.value.length}} / 100</span></mat-hint> <mat-hint align="start" class="error" *ngIf="emptyInputs"><strong>{{ 'home-page.no-empty-name' | translate }}</strong></mat-hint> </mat-form-field> - <mat-checkbox (change)="hasCustomShortId=$event.checked">create custom shortid</mat-checkbox> + <mat-checkbox (change)="hasCustomShortId=$event.checked">{{ 'home-page.custom-shortid' | translate }}</mat-checkbox> <mat-form-field *ngIf="hasCustomShortId"> <input (focus)="eventService.makeFocusOnInputTrue()" (blur)="eventService.makeFocusOnInputFalse()" @@ -31,20 +31,17 @@ #customShortId class="input-block" type="text" - maxlength="20" + maxlength="30" [(ngModel)]="customShortIdName" name="customShortId" aria-labelledby="room-name-input"/> - <mat-placeholder class="placeholder">custom shortid</mat-placeholder> + <mat-placeholder class="placeholder">{{ 'home-page.custom-shortid-placeholder' | translate }}</mat-placeholder> <mat-hint align="end" class="count" - *ngIf="!emptyInputs"><span aria-hidden="true">{{customShortId.value.length}} / 20</span></mat-hint> + *ngIf="!emptyInputs"><span aria-hidden="true">{{customShortId.value.length}} / 30</span></mat-hint> <mat-hint align="start" class="error" - *ngIf="shortIdAlreadyUsed"><strong>shortId already used</strong></mat-hint> - <mat-hint align="start" - class="error" - *ngIf="invalidShortId"><strong>invalid shortId</strong></mat-hint> + *ngIf="shortIdAlreadyUsed"><strong>{{ 'home-page.invalid-shortid' | translate }}</strong></mat-hint> </mat-form-field> </div> </form> diff --git a/src/app/components/shared/_dialogs/room-create/room-create.component.ts b/src/app/components/shared/_dialogs/room-create/room-create.component.ts index 4f3c086fc..817a99545 100644 --- a/src/app/components/shared/_dialogs/room-create/room-create.component.ts +++ b/src/app/components/shared/_dialogs/room-create/room-create.component.ts @@ -20,7 +20,6 @@ export class RoomCreateComponent implements OnInit { longName: string; customShortIdName: string; emptyInputs = false; - invalidShortId = false; shortIdAlreadyUsed = false; room: Room; roomId: string; @@ -64,12 +63,16 @@ export class RoomCreateComponent implements OnInit { this.emptyInputs = true; return; } - // check for custom short id const newRoom = new Room(); newRoom.name = longRoomName; newRoom.abbreviation = '00000000'; newRoom.description = ''; - this.roomService.addRoom(newRoom).subscribe(room => { + if (this.hasCustomShortId) { + newRoom.shortId = this.customShortIdName; + } + this.roomService.addRoom(newRoom, () => { + this.shortIdAlreadyUsed = true; + }).subscribe(room => { this.room = room; let msg1: string; let msg2: string; diff --git a/src/app/components/shared/header/header.component.html b/src/app/components/shared/header/header.component.html index e40db844a..432424e62 100644 --- a/src/app/components/shared/header/header.component.html +++ b/src/app/components/shared/header/header.component.html @@ -41,12 +41,13 @@ gavel </mat-icon> </span> + <!-- <h2 class="oldtypo-h2" id="shortId-header" *ngIf="router.url.includes('comments')" fxLayoutAlign="center center"> {{'header.id' | translate}}: {{ shortId.slice(0, 4) }} {{ shortId.slice(4, 8) }} - </h2> + </h2>--> <!--Feedback im Hörsaal--> <h2 class="oldtypo-h2" *ngIf="router.url.includes('home')" diff --git a/src/app/models/room.ts b/src/app/models/room.ts index f1af7606f..e83d37ce5 100644 --- a/src/app/models/room.ts +++ b/src/app/models/room.ts @@ -24,7 +24,7 @@ export class Room { moderated: boolean = true, directSend: boolean = true, threshold: number = null, - tags: string[] = [] + tags: string[] = [], ) { this.id = ''; this.ownerId = ownerId; diff --git a/src/app/services/http/room.service.ts b/src/app/services/http/room.service.ts index 3aff3f4c6..60b722f47 100644 --- a/src/app/services/http/room.service.ts +++ b/src/app/services/http/room.service.ts @@ -63,7 +63,7 @@ export class RoomService extends BaseHttpService { ); } - addRoom(room: Room): Observable<Room> { + addRoom(room: Room, exc?: () => void ): Observable<Room> { delete room.id; delete room.revision; const connectionUrl = this.apiUrl.base + this.apiUrl.rooms + '/'; @@ -72,7 +72,12 @@ export class RoomService extends BaseHttpService { tap(returnedRoom => { this.authService.setAccess(returnedRoom.shortId, UserRole.PARTICIPANT); }), - catchError(this.handleError<Room>(`add Room ${room}`)) + catchError(err => { + if (exc) { + exc(); + } + return this.handleError<Room>(`add Room ${room}`); + }) ); } diff --git a/src/assets/i18n/home/de.json b/src/assets/i18n/home/de.json index 75471c368..c482569ac 100644 --- a/src/assets/i18n/home/de.json +++ b/src/assets/i18n/home/de.json @@ -95,7 +95,10 @@ "please-enter": "Den Code sagt dir die Sitzungsleitung.", "room-name-input": "Gib hier den Namen der Sitzung, die du erstellen möchtest, ein.", "session-id": "Sitzungs-Name …", - "update-available": "Eine neue Version ist verfügbar." + "update-available": "Eine neue Version ist verfügbar.", + "custom-shortid": "e", + "custom-shortid-placeholder": "e", + "invalid-shortid": "e" }, "imprint": { "cancel": "Schließen", diff --git a/src/assets/i18n/home/en.json b/src/assets/i18n/home/en.json index 477040545..2a631143b 100644 --- a/src/assets/i18n/home/en.json +++ b/src/assets/i18n/home/en.json @@ -96,7 +96,10 @@ "please-enter": "Ask the speaker for the key.", "room-name-input": "Enter the name of the session you want to create here.", "session-id": "Session name …", - "update-available": "An update is available." + "update-available": "An update is available.", + "custom-shortid": "e", + "custom-shortid-placeholder": "e", + "invalid-shortid": "e" }, "imprint": { "cancel": "Close", -- GitLab