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

View File

@ -7,6 +7,7 @@ import {PhotoProcessing} from '../../fileprocessing/PhotoProcessing';
import {ThumbnailSourceType} from '../../threading/PhotoWorker';
import {MediaDTO} from '../../../../common/entities/MediaDTO';
import {FileDTO} from '../../../../common/entities/FileDTO';
import {backendTexts} from '../../../../common/BackendTexts';
const LOG_TAG = '[ThumbnailGenerationJob]';
@ -20,7 +21,8 @@ export class ThumbnailGenerationJob extends FileJob<{ sizes: number[], indexedOn
this.ConfigTemplate.push({
id: 'sizes',
type: 'number-array',
name: 'Sizes to generate',
name: backendTexts.sizeToGenerate.name,
description: backendTexts.sizeToGenerate.description,
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';
@ -12,7 +14,8 @@ export enum DefaultsJobs {
export interface ConfigTemplateEntry {
id: string;
name: string;
name: backendText;
description: backendText;
type: fieldType;
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 {JobsSettingsComponent} from './ui/settings/jobs/jobs.settings.component';
import {ScheduledJobsService} from './ui/settings/scheduled-jobs.service';
import {BackendtextService} from './model/backendtext.service';
@Injectable()
@ -230,6 +231,7 @@ export function translationsFactory(locale: string) {
FacesService,
VersionService,
ScheduledJobsService,
BackendtextService,
{
provide: TRANSLATIONS,
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) ">
<hr/>
<div *ngFor="let configEntry of getConfigTemplate(schedule.jobName)">
<ng-container [ngSwitch]="configEntry.type">
<ng-container *ngSwitchCase="'boolean'">
<div class="form-group row">
<label class="col-md-2 control-label"
[for]="configEntry.id+'_boolean_'+i">{{configEntry.name}}</label>
<div class="col-md-10">
<div class="form-group row">
<label class="col-md-2 control-label"
[for]="configEntry.id+'_'+i">{{backendtextService.get(configEntry.name)}}:</label>
<div class="col-md-10">
<ng-container [ngSwitch]="configEntry.type">
<ng-container *ngSwitchCase="'boolean'">
<bSwitch
id="enableThreading"
class="switch"
[name]="configEntry.id+'_boolean_'+i"
[id]="configEntry.id+'_boolean_'+i"
[name]="configEntry.id+'_'+i"
[id]="configEntry.id+'_'+i"
[switch-on-color]="'primary'"
[switch-inverse]="true"
[switch-off-text]="text.Disabled"
@ -157,48 +158,35 @@
[switch-label-width]="20"
[(ngModel)]="schedule.config[configEntry.id]">
</bSwitch>
</div>
</div>
</ng-container>
<ng-container *ngSwitchCase="'string'">
<div class="form-group row" [hidden]="simplifiedMode">
<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"
</ng-container>
<ng-container *ngSwitchCase="'string'">
<input type="text" class="form-control" [name]="configEntry.id+'_'+i"
[id]="configEntry.id+'_'+i"
[(ngModel)]="schedule.config[configEntry.id]" required>
</div>
</div>
</ng-container>
<ng-container *ngSwitchCase="'number'">
<div class="form-group row" [hidden]="simplifiedMode">
<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"
</ng-container>
<ng-container *ngSwitchCase="'number'">
<input type="number" class="form-control" [name]="configEntry.id+'_'+i"
[id]="configEntry.id+'_'+i"
[(ngModel)]="schedule.config[configEntry.id]" required>
</div>
</div>
</ng-container>
<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">
</ng-container>
<ng-container *ngSwitchCase="'number-array'">
<input type="text" class="form-control"
[name]="configEntry.id+'_number-array_'+i"
[id]="configEntry.id+'_number-array_'+i"
[name]="configEntry.id+'_'+i"
[id]="configEntry.id+'_'+i"
(ngModelChange)="setNumberArray(schedule.config,configEntry.id,$event)"
[ngModel]="getNumberArray(schedule.config,configEntry.id)" required>
<small class="form-text text-muted">
<ng-container i18n>';' separated integers.</ng-container>
</small>
</div>
</div>
</ng-container>
</ng-container>
</ng-container>
</ng-container>
<small class="form-text text-muted">
<ng-container *ngIf="configEntry.type == 'number-array'" i18n>';' separated integers.</ng-container>
{{backendtextService.get(configEntry.description)}}
</small>
</div>
</div>
</div>
</ng-container>
</div>

View File

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