Skip to content

Commit 1ce748f

Browse files
committed
Fully transition to using events for maintenance mode
1 parent b9e9001 commit 1ce748f

4 files changed

Lines changed: 32 additions & 19 deletions

File tree

assets/js/modules/angular/directives/qcAddItemDirective.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,13 @@ export class AddItemController extends SetValueControllerBase<AddItemController>
142142
}
143143

144144
_itemDataError(error: any) {
145-
this.$scope.safeApply(() => {
146-
this.items.length = 0;
147-
this.items.push(errorItem);
148-
});
145+
this.items.length = 0;
146+
this.items.push(errorItem);
149147
}
150148

151149
_maintenance() {
152-
this.$scope.safeApply(() => {
153-
this.items.length = 0;
154-
this.items.push(maintenanceItem);
155-
});
150+
this.items.length = 0;
151+
this.items.push(maintenanceItem);
156152
}
157153

158154
_updateValue() {

assets/js/modules/angular/directives/qcEditLogDirective.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ import constants from '../../../constants';
2424
import settings from '../../settings';
2525
import variables from '../../../../generated/variables.pass2';
2626

27+
import { EventHandlingControllerBase } from '../controllers/ControllerBases';
28+
2729
import type { $DecoratedScope } from '../decorateScope';
2830
import type { ComicService } from '../services/comicService';
2931
import type { EventService } from '../services/eventService';
3032
import type { MessageReportingService } from '../services/messageReportingService';
3133
import type { ComicData, ComicItem } from '../api/comicData';
3234
import type { LogEntryData } from '../api/logEntryData';
3335

34-
export class EditLogController {
36+
export class EditLogController extends EventHandlingControllerBase<EditLogController> {
3537
static $inject: string[];
3638

3739
$scope: $DecoratedScope<EditLogController>;
@@ -48,24 +50,31 @@ export class EditLogController {
4850
$scope: $DecoratedScope<EditLogController>,
4951
$log: $Log,
5052
$http: $Http,
51-
messageReportingService: MessageReportingService
53+
messageReportingService: MessageReportingService,
54+
eventService: EventService
5255
) {
5356
$log.debug('START EditLogController');
5457

55-
this.$scope = $scope;
58+
super($scope, eventService);
59+
5660
this.$log = $log;
5761
this.$http = $http;
5862
this.messageReportingService = messageReportingService;
5963

6064
this.currentPage = 1;
6165

6266
$('#editLogDialog').on('show.bs.modal', () => {
67+
this.currentPage = 1;
6368
this._loadLogs();
6469
});
6570

6671
$log.debug('END EditLogController');
6772
}
6873

74+
_maintenance() {
75+
this.close();
76+
}
77+
6978
async _loadLogs() {
7079
this.$scope.safeApply(() => {
7180
this.isLoading = true;
@@ -80,8 +89,7 @@ export class EditLogController {
8089
});
8190
} else {
8291
if (response.status === 503) {
83-
this.messageReportingService.reportError(constants.messages.maintenance);
84-
this.close();
92+
this.eventService.maintenanceEvent.publish();
8593
} else {
8694
this.messageReportingService.reportError(response.data);
8795
}
@@ -108,7 +116,7 @@ export class EditLogController {
108116
($('#editLogDialog'): any).modal('hide');
109117
}
110118
}
111-
EditLogController.$inject = ['$scope', '$log', '$http', 'messageReportingService'];
119+
EditLogController.$inject = ['$scope', '$log', '$http', 'messageReportingService', 'eventService'];
112120

113121
export default function (app: AngularModule) {
114122
app.directive('qcEditLog', function () {

assets/js/modules/angular/directives/qcExtraDirective.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class ExtraController extends EventHandlingControllerBase<ExtraController
4242
$log: $Log;
4343
$sce: $Sce;
4444
comicService: ComicService;
45+
messageReportingService: MessageReportingService;
4546

4647
settings: Settings;
4748
constants: *;
@@ -66,6 +67,7 @@ export class ExtraController extends EventHandlingControllerBase<ExtraController
6667
$sce: $Sce,
6768
comicService: ComicService,
6869
eventService: EventService,
70+
messageReportingService: MessageReportingService,
6971
latestComic: number
7072
) {
7173
$log.debug('START ExtraController');
@@ -75,6 +77,7 @@ export class ExtraController extends EventHandlingControllerBase<ExtraController
7577
this.$log = $log;
7678
this.$sce = $sce;
7779
this.comicService = comicService;
80+
this.messageReportingService = messageReportingService;
7881

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

93+
_maintenance() {
94+
this._reset();
95+
this.messages.push(constants.messages.maintenance);
96+
this.messageReportingService.reportError(constants.messages.maintenance);
97+
this.hasWarning = true;
98+
}
99+
90100
_comicDataLoading(comic: number) {
91101
this._loading();
92102
}
@@ -225,7 +235,7 @@ export class ExtraController extends EventHandlingControllerBase<ExtraController
225235
this.messages.push('Error communicating with server');
226236
this.hasError = true;
227237
} else {
228-
this.messages.push(constants.messages.maintenance);
238+
this.eventService.maintenanceEvent.publish();
229239
}
230240
}
231241

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

297307
export default function (app: AngularModule) {
298308
app.directive('qcExtra', function () {

assets/js/modules/angular/services/comicService.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ export class ComicService {
9898
if (response.status !== 503) {
9999
this.messageReportingService.reportError(response.data);
100100
} else {
101-
this.messageReportingService.reportError(
102-
constants.messages.maintenance);
101+
this.eventService.maintenanceEvent.publish();
103102
}
104103
return response;
105104
}
@@ -159,7 +158,7 @@ export class ComicService {
159158
this.$http.get(comicDataUrl)
160159
.then((response) => {
161160
if (response.status === 503) {
162-
this.eventService.comicDataErrorEvent.publish(response);
161+
this.eventService.maintenanceEvent.publish(response);
163162
return;
164163
}
165164
if (response.status !== 200) {

0 commit comments

Comments
 (0)