Skip to content

Commit

Permalink
Fully transition to using events for maintenance mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyvion committed Mar 8, 2019
1 parent b9e9001 commit 1ce748f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
12 changes: 4 additions & 8 deletions assets/js/modules/angular/directives/qcAddItemDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,13 @@ export class AddItemController extends SetValueControllerBase<AddItemController>
}

_itemDataError(error: any) {
this.$scope.safeApply(() => {
this.items.length = 0;
this.items.push(errorItem);
});
this.items.length = 0;
this.items.push(errorItem);
}

_maintenance() {
this.$scope.safeApply(() => {
this.items.length = 0;
this.items.push(maintenanceItem);
});
this.items.length = 0;
this.items.push(maintenanceItem);
}

_updateValue() {
Expand Down
20 changes: 14 additions & 6 deletions assets/js/modules/angular/directives/qcEditLogDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ import constants from '../../../constants';
import settings from '../../settings';
import variables from '../../../../generated/variables.pass2';

import { EventHandlingControllerBase } from '../controllers/ControllerBases';

import type { $DecoratedScope } from '../decorateScope';
import type { ComicService } from '../services/comicService';
import type { EventService } from '../services/eventService';
import type { MessageReportingService } from '../services/messageReportingService';
import type { ComicData, ComicItem } from '../api/comicData';
import type { LogEntryData } from '../api/logEntryData';

export class EditLogController {
export class EditLogController extends EventHandlingControllerBase<EditLogController> {
static $inject: string[];

$scope: $DecoratedScope<EditLogController>;
Expand All @@ -48,24 +50,31 @@ export class EditLogController {
$scope: $DecoratedScope<EditLogController>,
$log: $Log,
$http: $Http,
messageReportingService: MessageReportingService
messageReportingService: MessageReportingService,
eventService: EventService
) {
$log.debug('START EditLogController');

this.$scope = $scope;
super($scope, eventService);

this.$log = $log;
this.$http = $http;
this.messageReportingService = messageReportingService;

this.currentPage = 1;

$('#editLogDialog').on('show.bs.modal', () => {
this.currentPage = 1;
this._loadLogs();
});

$log.debug('END EditLogController');
}

_maintenance() {
this.close();
}

async _loadLogs() {
this.$scope.safeApply(() => {
this.isLoading = true;
Expand All @@ -80,8 +89,7 @@ export class EditLogController {
});
} else {
if (response.status === 503) {
this.messageReportingService.reportError(constants.messages.maintenance);
this.close();
this.eventService.maintenanceEvent.publish();
} else {
this.messageReportingService.reportError(response.data);
}
Expand All @@ -108,7 +116,7 @@ export class EditLogController {
($('#editLogDialog'): any).modal('hide');
}
}
EditLogController.$inject = ['$scope', '$log', '$http', 'messageReportingService'];
EditLogController.$inject = ['$scope', '$log', '$http', 'messageReportingService', 'eventService'];

export default function (app: AngularModule) {
app.directive('qcEditLog', function () {
Expand Down
14 changes: 12 additions & 2 deletions assets/js/modules/angular/directives/qcExtraDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class ExtraController extends EventHandlingControllerBase<ExtraController
$log: $Log;
$sce: $Sce;
comicService: ComicService;
messageReportingService: MessageReportingService;

settings: Settings;
constants: *;
Expand All @@ -66,6 +67,7 @@ export class ExtraController extends EventHandlingControllerBase<ExtraController
$sce: $Sce,
comicService: ComicService,
eventService: EventService,
messageReportingService: MessageReportingService,
latestComic: number
) {
$log.debug('START ExtraController');
Expand All @@ -75,6 +77,7 @@ export class ExtraController extends EventHandlingControllerBase<ExtraController
this.$log = $log;
this.$sce = $sce;
this.comicService = comicService;
this.messageReportingService = messageReportingService;

this.settings = settings;
this.constants = constants;
Expand All @@ -87,6 +90,13 @@ export class ExtraController extends EventHandlingControllerBase<ExtraController
$log.debug('END ExtraController');
}

_maintenance() {
this._reset();
this.messages.push(constants.messages.maintenance);
this.messageReportingService.reportError(constants.messages.maintenance);
this.hasWarning = true;
}

_comicDataLoading(comic: number) {
this._loading();
}
Expand Down Expand Up @@ -225,7 +235,7 @@ export class ExtraController extends EventHandlingControllerBase<ExtraController
this.messages.push('Error communicating with server');
this.hasError = true;
} else {
this.messages.push(constants.messages.maintenance);
this.eventService.maintenanceEvent.publish();
}
}

Expand Down Expand Up @@ -292,7 +302,7 @@ export class ExtraController extends EventHandlingControllerBase<ExtraController
($('#changeLogDialog'): any).modal('show');
}
}
ExtraController.$inject = ['$scope', '$log', '$sce', 'comicService', 'eventService', 'latestComic'];
ExtraController.$inject = ['$scope', '$log', '$sce', 'comicService', 'eventService', 'messageReportingService', 'latestComic'];

export default function (app: AngularModule) {
app.directive('qcExtra', function () {
Expand Down
5 changes: 2 additions & 3 deletions assets/js/modules/angular/services/comicService.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ export class ComicService {
if (response.status !== 503) {
this.messageReportingService.reportError(response.data);
} else {
this.messageReportingService.reportError(
constants.messages.maintenance);
this.eventService.maintenanceEvent.publish();
}
return response;
}
Expand Down Expand Up @@ -159,7 +158,7 @@ export class ComicService {
this.$http.get(comicDataUrl)
.then((response) => {
if (response.status === 503) {
this.eventService.comicDataErrorEvent.publish(response);
this.eventService.maintenanceEvent.publish(response);
return;
}
if (response.status !== 200) {
Expand Down

0 comments on commit 1ce748f

Please sign in to comment.