1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

creating backend text for jobs

This commit is contained in:
Patrik J. Braun 2019-12-29 10:24:47 +01:00
parent 95a50b4936
commit cc83dc718d
10 changed files with 132 additions and 49 deletions

View File

@ -11,6 +11,7 @@ import {SQLConnection} from '../../database/sql/SQLConnection';
import {MediaEntity} from '../../database/sql/enitites/MediaEntity'; import {MediaEntity} from '../../database/sql/enitites/MediaEntity';
import {PhotoEntity} from '../../database/sql/enitites/PhotoEntity'; import {PhotoEntity} from '../../database/sql/enitites/PhotoEntity';
import {VideoEntity} from '../../database/sql/enitites/VideoEntity'; import {VideoEntity} from '../../database/sql/enitites/VideoEntity';
import {backendTexts} from '../../../../common/BackendTexts';
import DatabaseType = ServerConfig.DatabaseType; import DatabaseType = ServerConfig.DatabaseType;
declare var global: NodeJS.Global; declare var global: NodeJS.Global;
@ -31,7 +32,8 @@ export abstract class FileJob<S extends { indexedOnly: boolean } = { indexedOnly
this.ConfigTemplate.push({ this.ConfigTemplate.push({
id: 'indexedOnly', id: 'indexedOnly',
type: 'boolean', type: 'boolean',
name: 'Only indexed files', name: backendTexts.indexedFilesOnly.name,
description: backendTexts.indexedFilesOnly.description,
defaultValue: true defaultValue: true
}); });
} }
@ -53,6 +55,7 @@ export abstract class FileJob<S extends { indexedOnly: boolean } = { indexedOnly
} }
protected abstract async shouldProcess(file: FileDTO): Promise<boolean>; protected abstract async shouldProcess(file: FileDTO): Promise<boolean>;
protected abstract async processFile(file: FileDTO): Promise<void>; protected abstract async processFile(file: FileDTO): Promise<void>;
protected async step(): Promise<boolean> { protected async step(): Promise<boolean> {
@ -79,7 +82,7 @@ export abstract class FileJob<S extends { indexedOnly: boolean } = { indexedOnly
this.Progress.log('processing: ' + filePath); this.Progress.log('processing: ' + filePath);
await this.processFile(file); await this.processFile(file);
} else { } else {
this.Progress.log('skipping: ' + filePath); this.Progress.log('skipping: ' + filePath);
this.Progress.Skipped++; this.Progress.Skipped++;
} }
} catch (e) { } catch (e) {

View File

@ -7,6 +7,7 @@ import {PhotoProcessing} from '../../fileprocessing/PhotoProcessing';
import {ThumbnailSourceType} from '../../threading/PhotoWorker'; import {ThumbnailSourceType} from '../../threading/PhotoWorker';
import {MediaDTO} from '../../../../common/entities/MediaDTO'; import {MediaDTO} from '../../../../common/entities/MediaDTO';
import {FileDTO} from '../../../../common/entities/FileDTO'; import {FileDTO} from '../../../../common/entities/FileDTO';
import {backendTexts} from '../../../../common/BackendTexts';
const LOG_TAG = '[ThumbnailGenerationJob]'; const LOG_TAG = '[ThumbnailGenerationJob]';
@ -20,7 +21,8 @@ export class ThumbnailGenerationJob extends FileJob<{ sizes: number[], indexedOn
this.ConfigTemplate.push({ this.ConfigTemplate.push({
id: 'sizes', id: 'sizes',
type: 'number-array', type: 'number-array',
name: 'Sizes to generate', name: backendTexts.sizeToGenerate.name,
description: backendTexts.sizeToGenerate.description,
defaultValue: [Config.Client.Media.Thumbnail.thumbnailSizes[0]] defaultValue: [Config.Client.Media.Thumbnail.thumbnailSizes[0]]
}); });
} }

View File

@ -0,0 +1,5 @@
export type backendText = number;
export const backendTexts = {
indexedFilesOnly: {name: 10, description: 12},
sizeToGenerate: {name: 20, description: 22}
};

View File

@ -1,3 +1,5 @@
import {backendText} from '../../BackendTexts';
export type fieldType = 'string' | 'number' | 'boolean' | 'number-array'; export type fieldType = 'string' | 'number' | 'boolean' | 'number-array';
@ -12,7 +14,8 @@ export enum DefaultsJobs {
export interface ConfigTemplateEntry { export interface ConfigTemplateEntry {
id: string; id: string;
name: string; name: backendText;
description: backendText;
type: fieldType; type: fieldType;
defaultValue: any; defaultValue: any;
} }

View File

@ -88,6 +88,7 @@ import {PhotoSettingsComponent} from './ui/settings/photo/photo.settings.compone
import {JobProgressComponent} from './ui/settings/jobs/progress/job-progress.settings.component'; import {JobProgressComponent} from './ui/settings/jobs/progress/job-progress.settings.component';
import {JobsSettingsComponent} from './ui/settings/jobs/jobs.settings.component'; import {JobsSettingsComponent} from './ui/settings/jobs/jobs.settings.component';
import {ScheduledJobsService} from './ui/settings/scheduled-jobs.service'; import {ScheduledJobsService} from './ui/settings/scheduled-jobs.service';
import {BackendtextService} from './model/backendtext.service';
@Injectable() @Injectable()
@ -230,6 +231,7 @@ export function translationsFactory(locale: string) {
FacesService, FacesService,
VersionService, VersionService,
ScheduledJobsService, ScheduledJobsService,
BackendtextService,
{ {
provide: TRANSLATIONS, provide: TRANSLATIONS,
useFactory: translationsFactory, useFactory: translationsFactory,

View File

@ -0,0 +1,32 @@
import {inject, TestBed} from '@angular/core/testing';
import {I18n} from '@ngx-translate/i18n-polyfill';
import {BackendtextService} from './backendtext.service';
import {backendTexts} from '../../../common/BackendTexts';
describe('BackendTextService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{provide: I18n, useValue: () => 'ok'},
BackendtextService
]
});
});
it('should call UserDTO service login', inject([BackendtextService],
(backendTextService: BackendtextService) => {
const getTexts = (obj: any) => {
for (const key of Object.keys(obj)) {
if (typeof obj[key] === 'object') {
getTexts(obj[key]);
continue;
}
expect(backendTextService.get(obj[key])).not.toBe(null);
}
};
getTexts(backendTexts);
}));
});

View File

@ -0,0 +1,26 @@
import {Injectable} from '@angular/core';
import {I18n} from '@ngx-translate/i18n-polyfill';
import {backendText, backendTexts} from '../../../common/BackendTexts';
@Injectable()
export class BackendtextService {
constructor(private i18n: I18n) {
}
public get(id: backendText): string {
switch (id) {
case backendTexts.sizeToGenerate.name:
return this.i18n('Size to generate');
case backendTexts.sizeToGenerate.description:
return this.i18n('These thumbnails will be generated. The list should be a subset of the enabled thumbnail sizes');
case backendTexts.indexedFilesOnly.name:
return this.i18n('Indexed only');
case backendTexts.indexedFilesOnly.description:
return this.i18n('Only checks indexed files.');
default:
return null;
}
}
}

View File

@ -138,17 +138,18 @@
<ng-container *ngIf="getConfigTemplate(schedule.jobName) "> <ng-container *ngIf="getConfigTemplate(schedule.jobName) ">
<hr/> <hr/>
<div *ngFor="let configEntry of getConfigTemplate(schedule.jobName)"> <div *ngFor="let configEntry of getConfigTemplate(schedule.jobName)">
<ng-container [ngSwitch]="configEntry.type">
<ng-container *ngSwitchCase="'boolean'"> <div class="form-group row">
<div class="form-group row"> <label class="col-md-2 control-label"
<label class="col-md-2 control-label" [for]="configEntry.id+'_'+i">{{backendtextService.get(configEntry.name)}}:</label>
[for]="configEntry.id+'_boolean_'+i">{{configEntry.name}}</label> <div class="col-md-10">
<div class="col-md-10"> <ng-container [ngSwitch]="configEntry.type">
<ng-container *ngSwitchCase="'boolean'">
<bSwitch <bSwitch
id="enableThreading" id="enableThreading"
class="switch" class="switch"
[name]="configEntry.id+'_boolean_'+i" [name]="configEntry.id+'_'+i"
[id]="configEntry.id+'_boolean_'+i" [id]="configEntry.id+'_'+i"
[switch-on-color]="'primary'" [switch-on-color]="'primary'"
[switch-inverse]="true" [switch-inverse]="true"
[switch-off-text]="text.Disabled" [switch-off-text]="text.Disabled"
@ -157,48 +158,35 @@
[switch-label-width]="20" [switch-label-width]="20"
[(ngModel)]="schedule.config[configEntry.id]"> [(ngModel)]="schedule.config[configEntry.id]">
</bSwitch> </bSwitch>
</div> </ng-container>
</div>
</ng-container> <ng-container *ngSwitchCase="'string'">
<ng-container *ngSwitchCase="'string'"> <input type="text" class="form-control" [name]="configEntry.id+'_'+i"
<div class="form-group row" [hidden]="simplifiedMode"> [id]="configEntry.id+'_'+i"
<label class="col-md-2 control-label"
[for]="configEntry.id+'_string_'+i">{{configEntry.name}}</label>
<div class="col-md-10">
<input type="text" class="form-control" [name]="configEntry.id+'_string_'+i"
[id]="configEntry.id+'_string_'+i"
[(ngModel)]="schedule.config[configEntry.id]" required> [(ngModel)]="schedule.config[configEntry.id]" required>
</div> </ng-container>
</div>
</ng-container> <ng-container *ngSwitchCase="'number'">
<ng-container *ngSwitchCase="'number'"> <input type="number" class="form-control" [name]="configEntry.id+'_'+i"
<div class="form-group row" [hidden]="simplifiedMode"> [id]="configEntry.id+'_'+i"
<label class="col-md-2 control-label"
[for]="configEntry.id+'_number_'+i">{{configEntry.name}}</label>
<div class="col-md-10">
<input type="number" class="form-control" [name]="configEntry.id+'_number_'+i"
[id]="configEntry.id+'_number_'+i"
[(ngModel)]="schedule.config[configEntry.id]" required> [(ngModel)]="schedule.config[configEntry.id]" required>
</div> </ng-container>
</div>
</ng-container> <ng-container *ngSwitchCase="'number-array'">
<ng-container *ngSwitchCase="'number-array'">
<div class="form-group row" [hidden]="simplifiedMode">
<label class="col-md-2 control-label"
[for]="configEntry.id+'_number-array_'+i">{{configEntry.name}}</label>
<div class="col-md-10">
<input type="text" class="form-control" <input type="text" class="form-control"
[name]="configEntry.id+'_number-array_'+i" [name]="configEntry.id+'_'+i"
[id]="configEntry.id+'_number-array_'+i" [id]="configEntry.id+'_'+i"
(ngModelChange)="setNumberArray(schedule.config,configEntry.id,$event)" (ngModelChange)="setNumberArray(schedule.config,configEntry.id,$event)"
[ngModel]="getNumberArray(schedule.config,configEntry.id)" required> [ngModel]="getNumberArray(schedule.config,configEntry.id)" required>
<small class="form-text text-muted"> </ng-container>
<ng-container i18n>';' separated integers.</ng-container> </ng-container>
</small> <small class="form-text text-muted">
</div> <ng-container *ngIf="configEntry.type == 'number-array'" i18n>';' separated integers.</ng-container>
</div> {{backendtextService.get(configEntry.description)}}
</ng-container> </small>
</ng-container> </div>
</div>
</div> </div>
</ng-container> </ng-container>
</div> </div>

View File

@ -21,6 +21,7 @@ import {ConfigTemplateEntry, JobDTO} from '../../../../../common/entities/job/Jo
import {Job} from '../../../../../backend/model/jobs/jobs/Job'; import {Job} from '../../../../../backend/model/jobs/jobs/Job';
import {ModalDirective} from 'ngx-bootstrap/modal'; import {ModalDirective} from 'ngx-bootstrap/modal';
import {JobProgressStates} from '../../../../../common/entities/job/JobProgressDTO'; import {JobProgressStates} from '../../../../../common/entities/job/JobProgressDTO';
import {BackendtextService} from '../../../model/backendtext.service';
@Component({ @Component({
selector: 'app-settings-jobs', selector: 'app-settings-jobs',
@ -52,6 +53,7 @@ export class JobsSettingsComponent extends SettingsComponent<ServerConfig.JobCon
_navigation: NavigationService, _navigation: NavigationService,
_settingsService: JobsSettingsService, _settingsService: JobsSettingsService,
public jobsService: ScheduledJobsService, public jobsService: ScheduledJobsService,
public backendtextService: BackendtextService,
notification: NotificationService, notification: NotificationService,
i18n: I18n) { i18n: I18n) {

View File

@ -0,0 +1,20 @@
import {expect} from 'chai';
import {backendTexts} from '../../../src/common/BackendTexts';
describe('BackendText', () => {
it('should all number be unique', () => {
const numbers: number[] = [];
const getNumbers = (obj: any) => {
for (const key of Object.keys(obj)) {
if (typeof obj[key] === 'object') {
getNumbers(obj[key]);
continue;
}
expect(numbers.indexOf(obj[key])).to.be.equal(-1, 'duplicate backend number id found:' + obj[key]);
numbers.push(obj[key]);
}
};
getNumbers(backendTexts);
});
});