From b9923201e4f9e90c9007824b6347e40a6b44fe72 Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Mon, 25 Feb 2019 14:19:56 +0100 Subject: [PATCH] Add small fixes Fixes an error where the back arrow in the motion block detail was missing Adds a prompt before deletion of Change Recommendation in motion details Adds timestamp localisation for history mode --- .../openslides-status.service.ts | 30 +++++++++++++------ .../core/core-services/time-travel.service.ts | 12 ++++---- client/src/app/shared/models/core/history.ts | 10 +++++++ client/src/app/shared/utils/lang-to-locale.ts | 23 ++++++++++++++ .../history-list/history-list.component.html | 2 +- .../history-list/history-list.component.ts | 11 ++++--- .../app/site/history/models/view-history.ts | 10 ------- .../motion-block-detail.component.html | 2 +- .../motion-detail-diff.component.ts | 27 ++++++++++------- client/src/app/site/site.component.html | 7 ++--- client/src/app/site/site.component.scss | 8 ++--- client/src/app/site/site.component.ts | 11 +++++++ 12 files changed, 102 insertions(+), 51 deletions(-) create mode 100644 client/src/app/shared/utils/lang-to-locale.ts diff --git a/client/src/app/core/core-services/openslides-status.service.ts b/client/src/app/core/core-services/openslides-status.service.ts index 410d676ec..90775c564 100644 --- a/client/src/app/core/core-services/openslides-status.service.ts +++ b/client/src/app/core/core-services/openslides-status.service.ts @@ -1,5 +1,7 @@ import { Injectable } from '@angular/core'; +import { History } from 'app/shared/models/core/history'; + /** * Holds information about OpenSlides. This is not included into other services to * avoid circular dependencies. @@ -9,15 +11,15 @@ import { Injectable } from '@angular/core'; }) export class OpenSlidesStatusService { /** - * Saves, if OpenSlides is in the history mode. + * in History mode, saves the history point. */ - private historyMode = false; + private history: History = null; /** * Returns, if OpenSlides is in the history mode. */ public get isInHistoryMode(): boolean { - return this.historyMode; + return !!this.history; } /** @@ -26,16 +28,26 @@ export class OpenSlidesStatusService { public constructor() {} /** - * Enters the histroy mode + * Calls the getLocaleString function of the history object, if present. + * + * @param format the required date representation format + * @returns the timestamp as string */ - public enterHistoryMode(): void { - this.historyMode = true; + public getHistoryTimeStamp(format: string): string { + return this.history ? this.history.getLocaleString(format) : null; } /** - * Leaves the histroy mode + * Enters the history mode */ - public leaveHistroyMode(): void { - this.historyMode = false; + public enterHistoryMode(history: History): void { + this.history = history; + } + + /** + * Leaves the history mode + */ + public leaveHistoryMode(): void { + this.history = null; } } diff --git a/client/src/app/core/core-services/time-travel.service.ts b/client/src/app/core/core-services/time-travel.service.ts index e36e155c7..fcc823270 100644 --- a/client/src/app/core/core-services/time-travel.service.ts +++ b/client/src/app/core/core-services/time-travel.service.ts @@ -60,7 +60,7 @@ export class TimeTravelService { * @param history the desired point in the history of OpenSlides */ public async loadHistoryPoint(history: History): Promise { - await this.stopTime(); + await this.stopTime(history); const fullDataHistory: HistoryData[] = await this.getHistoryData(history); for (const historyObject of fullDataHistory) { let collectionString: string; @@ -78,13 +78,13 @@ export class TimeTravelService { /** * Leaves the history mode. Just restart OpenSlides: - * The active user is chacked, a new WS connection established and - * all missed autoupdates are requested. + * The active user is checked, a new WS connection established and + * all missed auto updates are requested. */ public async resumeTime(): Promise { await this.DS.set(); await this.OpenSlides.reboot(); - this.OSStatus.leaveHistroyMode(); + this.OSStatus.leaveHistoryMode(); } /** @@ -102,10 +102,10 @@ export class TimeTravelService { /** * Clears the DataStore and stops the WebSocket connection */ - private async stopTime(): Promise { + private async stopTime(history: History): Promise { this.webSocketService.close(); await this.cleanDataStore(); - this.OSStatus.enterHistoryMode(); + this.OSStatus.enterHistoryMode(history); } /** diff --git a/client/src/app/shared/models/core/history.ts b/client/src/app/shared/models/core/history.ts index b894a3fa4..87f4730d0 100644 --- a/client/src/app/shared/models/core/history.ts +++ b/client/src/app/shared/models/core/history.ts @@ -32,4 +32,14 @@ export class History extends BaseModel { public constructor(input?: any) { super(History.COLLECTIONSTRING, input); } + + /** + * Converts the date (this.now) to a time and date string. + * + * @param locale locale indicator, i.e 'de-DE' + * @returns a human readable kind of time and date representation + */ + public getLocaleString(locale: string): string { + return this.date.toLocaleString(locale); + } } diff --git a/client/src/app/shared/utils/lang-to-locale.ts b/client/src/app/shared/utils/lang-to-locale.ts new file mode 100644 index 000000000..ef7dec694 --- /dev/null +++ b/client/src/app/shared/utils/lang-to-locale.ts @@ -0,0 +1,23 @@ +/** + * Helper function to convert a language indicator (en, de) + * to a locale indicator (de-DE, en-US) + * + * Necessary to correctly format timestamps + */ +export function langToLocale(lang: string): string { + switch (lang) { + case 'en': { + return 'en-GB'; + } + case 'de': { + return 'de-DE'; + } + case 'cz': { + return 'cs-CZ'; + } + default: { + // has YYYY-MM-DD HH:mm:SS + return 'lt-LT'; + } + } +} diff --git a/client/src/app/site/history/components/history-list/history-list.component.html b/client/src/app/site/history/components/history-list/history-list.component.html index 79773a23d..16f09edee 100644 --- a/client/src/app/site/history/components/history-list/history-list.component.html +++ b/client/src/app/site/history/components/history-list/history-list.component.html @@ -21,7 +21,7 @@ Timestamp - {{ history.getLocaleString('DE-de') }} + {{ getTimestamp(history) }} diff --git a/client/src/app/site/history/components/history-list/history-list.component.ts b/client/src/app/site/history/components/history-list/history-list.component.ts index 8b41437dd..11427b8d9 100644 --- a/client/src/app/site/history/components/history-list/history-list.component.ts +++ b/client/src/app/site/history/components/history-list/history-list.component.ts @@ -13,6 +13,7 @@ import { ListViewBaseComponent } from 'app/site/base/list-view-base'; import { OperatorService } from 'app/core/core-services/operator.service'; import { ViewHistory } from '../../models/view-history'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; +import { langToLocale } from 'app/shared/utils/lang-to-locale'; /** * A list view for the history. @@ -113,17 +114,19 @@ export class HistoryListComponent extends ListViewBaseComponent +

{{ block.title }}

diff --git a/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.ts b/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.ts index 3dc014880..eb930c22c 100644 --- a/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.ts +++ b/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.ts @@ -4,18 +4,19 @@ import { DomSanitizer, SafeHtml, Title } from '@angular/platform-browser'; import { TranslateService } from '@ngx-translate/core'; -import { LineNumberingMode, ViewMotion } from '../../models/view-motion'; -import { ViewUnifiedChange, ViewUnifiedChangeType } from '../../../../shared/models/motions/view-unified-change'; -import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; -import { DiffService, LineRange, ModificationType } from 'app/core/ui-services/diff.service'; -import { ViewMotionChangeRecommendation } from '../../models/view-change-recommendation'; +import { BaseViewComponent } from '../../../base/base-view'; +import { ConfigService } from 'app/core/ui-services/config.service'; import { ChangeRecommendationRepositoryService } from 'app/core/repositories/motions/change-recommendation-repository.service'; +import { DiffService, LineRange, ModificationType } from 'app/core/ui-services/diff.service'; +import { LineNumberingMode, ViewMotion } from '../../models/view-motion'; import { MotionChangeRecommendationComponent, MotionChangeRecommendationComponentData } from '../motion-change-recommendation/motion-change-recommendation.component'; -import { BaseViewComponent } from '../../../base/base-view'; -import { ConfigService } from 'app/core/ui-services/config.service'; +import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; +import { PromptService } from 'app/core/ui-services/prompt.service'; +import { ViewUnifiedChange, ViewUnifiedChangeType } from '../../../../shared/models/motions/view-unified-change'; +import { ViewMotionChangeRecommendation } from '../../models/view-change-recommendation'; /** * This component displays the original motion text with the change blocks inside. @@ -74,6 +75,7 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte * @param dialogService * @param configService * @param el + * @param promptService */ public constructor( title: Title, @@ -85,10 +87,10 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte private recoRepo: ChangeRecommendationRepositoryService, private dialogService: MatDialog, private configService: ConfigService, - private el: ElementRef + private el: ElementRef, + private promptService: PromptService ) { super(title, translate, matSnackBar); - this.configService.get('motions_line_length').subscribe(lineLength => (this.lineLength = lineLength)); } @@ -287,10 +289,13 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte * @param {ViewMotionChangeRecommendation} reco * @param {MouseEvent} $event */ - public deleteChangeRecommendation(reco: ViewMotionChangeRecommendation, $event: MouseEvent): void { + public async deleteChangeRecommendation(reco: ViewMotionChangeRecommendation, $event: MouseEvent): Promise { $event.stopPropagation(); $event.preventDefault(); - this.recoRepo.delete(reco).then(null, this.raiseError); + const content = this.translate.instant('Delete this change recommendation'); + if (await this.promptService.open('Are you sure?', content)) { + this.recoRepo.delete(reco).then(null, this.raiseError); + } } /** diff --git a/client/src/app/site/site.component.html b/client/src/app/site/site.component.html index 4613be0aa..f5a50e329 100644 --- a/client/src/app/site/site.component.html +++ b/client/src/app/site/site.component.html @@ -1,5 +1,6 @@
You are using the history mode of OpenSlides. Changes will not be saved. + ({{ getHistoryTimestamp() }}) Exit
@@ -29,11 +30,7 @@ {{ getLangName(this.translate.currentLang) }}
- + person Show profile diff --git a/client/src/app/site/site.component.scss b/client/src/app/site/site.component.scss index e73b3b2fc..a759df260 100644 --- a/client/src/app/site/site.component.scss +++ b/client/src/app/site/site.component.scss @@ -86,13 +86,13 @@ mat-sidenav-container { /* History mode top bar*/ .history-mode-indicator { - position: fixed; + position: relative; // was fixed before to prevent the overflow + min-height: 20px; + line-height: 20px; width: 100%; - z-index: 10; + // z-index: 10; background: repeating-linear-gradient(45deg, #ffee00, #ffee00 10px, #070600 10px, #000000 20px); text-align: center; - line-height: 20px; - height: 20px; span { padding: 2px; diff --git a/client/src/app/site/site.component.ts b/client/src/app/site/site.component.ts index f393ae4e8..8c2cb630c 100644 --- a/client/src/app/site/site.component.ts +++ b/client/src/app/site/site.component.ts @@ -13,6 +13,7 @@ import { ViewportService } from '../core/ui-services/viewport.service'; import { MainMenuService } from '../core/core-services/main-menu.service'; import { OpenSlidesStatusService } from '../core/core-services/openslides-status.service'; import { TimeTravelService } from '../core/core-services/time-travel.service'; +import { langToLocale } from 'app/shared/utils/lang-to-locale'; @Component({ selector: 'os-site', @@ -194,4 +195,14 @@ export class SiteComponent extends BaseComponent implements OnInit { this.searchform.reset(); this.router.navigate(['/search'], { queryParams: { query: query } }); } + + /** + * Get the timestamp for the current point in history mode. + * Tries to detect the ideal timestamp format using the translation service + * + * @returns the timestamp as string + */ + public getHistoryTimestamp(): string { + return this.OSStatus.getHistoryTimeStamp(langToLocale(this.translate.currentLang)); + } }