Skip to content

Commit

Permalink
Issue #122
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-stastny committed Mar 2, 2024
1 parent 1d00350 commit c2baa0e
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ <h2 mat-dialog-title>{{ mode == 'new' ? ('modal.createOrEditLicense.title.new' |
</mat-form-field>
</form>

<mat-checkbox [(ngModel)]="turnOnLock" class="app-mb-4 app-mt-4">{{ 'desc.turnOnTheLock' | translate }}</mat-checkbox>
<ng-container *ngIf="turnOnLock">

<mat-checkbox [(ngModel)]="license.exclusiveLock" class="app-mb-4 app-mt-4">{{ 'desc.turnOnTheLock' | translate }}</mat-checkbox>
<ng-container *ngIf="license.exclusiveLock">
<mat-form-field class="app-w-100">
<mat-label>{{ 'desc.maximumReadingTime' | translate }}</mat-label>
<input matInput [placeholder]="'desc.maximumReadingTime' | translate">
<mat-label>{{ formatedMaxTime() }}</mat-label>
<input matInput [placeholder]="'desc.maximumReadingTime' | translate" [(ngModel)]="license.max">
</mat-form-field>
<mat-form-field class="app-w-100">
<mat-label>{{ 'desc.refreshInterval' | translate }}</mat-label>
<input matInput [placeholder]="'desc.refreshInterval' | translate">
<input matInput [placeholder]="'desc.refreshInterval' | translate" [(ngModel)]="license.refresh">
</mat-form-field>
<mat-form-field class="app-w-100">
<mat-label>{{ 'desc.numberOfReadersReadingConcurrently' | translate }}</mat-label>
<input matInput [placeholder]="'desc.numberOfReadersReadingConcurrently' | translate">
<input matInput [placeholder]="'desc.numberOfReadersReadingConcurrently' | translate" [(ngModel)]="license.readers">
</mat-form-field>
</ng-container>
</mat-dialog-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class CreateOrEditLicenseDialogComponent implements OnInit {
licenseForm: FormGroup;

licenseNames: string[];

libraryName:string;

license: License;
Expand Down Expand Up @@ -60,15 +59,22 @@ export class CreateOrEditLicenseDialogComponent implements OnInit {
]],
licenseDesc: ['', Validators.required]
});


// default value for exclusive lock
this.license.exclusiveLock = false;
this.license.refresh = 20;
this.license.max = 10000;
this.license.readers = 1;

}


this.licenseName.markAsTouched();
this.licenseDesc.markAsTouched();

}



get licenseName() {
return this.licenseForm.get('licenseName');
}
Expand All @@ -78,6 +84,33 @@ export class CreateOrEditLicenseDialogComponent implements OnInit {
}


formatedMaxTime() {
if (this.license.max > 0) {
return "Zadáno v sekundách - "+this.formatTime(this.license.max);
}
}

formatTime(seconds: number): string {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const remainingSeconds = seconds % 60;

const hoursStr = hours === 1 ? '1 hodina' : `${hours} hodiny`;
const minutesStr = minutes === 1 ? '1 minuta' : `${minutes} minuty`;
const secondsStr = remainingSeconds === 1 ? '1 sekunda' : `${remainingSeconds} sekundy`;

const timeComponents = [];
if (hours > 0) {
timeComponents.push(hoursStr);
}
if (minutes > 0) {
timeComponents.push(minutesStr);
}
timeComponents.push(secondsStr);

return timeComponents.join(' a ');
}

onKeyUp() {
this.licenseName.markAsTouched();
this.licenseDesc.markAsTouched();
Expand Down
35 changes: 34 additions & 1 deletion src/app/models/license.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export class License {
priority: number;
group:string;

exclusiveLock: boolean = false;
refresh:number = -1;
max:number = -1;
readers: number = -1;




Expand All @@ -24,6 +29,19 @@ export class License {
license.priority = json['priority'];
license.group = json['group'];

/*
private static final String MAXREADERS_KEY = "maxreaders";
private static final String REFRESHINTERVAL_KEY = "refreshinterval";
private static final String MAXINTERVAL_KEY = "maxinterval";
private static final String EXCLUSIVE_KEY = "exclusive";
*/

license.exclusiveLock=json["exclusive"];
license.refresh=json["refreshinterval"];
license.max=json["maxinterval"];
license.readers=json["maxreaders"];


return license;

}
Expand All @@ -41,15 +59,30 @@ export class License {
this.priority = license.priority;
this.name = license.name;
this.description = license.description || '';

this.exclusiveLock = license.exclusiveLock;
this.refresh = license.refresh;
this.max = license.max;
this.readers = license.readers;

}

toJson() {
return {
let retval = {
id: this.id,
priority: this.priority,
name: this.name,
description: this.description || ''
};

if (this.exclusiveLock) {
retval['exclusive']= true;
retval['refreshinterval']= this.refresh;
retval['maxinterval']= this.max;
retval['maxreaders']= this.readers;
}

return retval;
}


Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/access/licenses/licenses.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<mat-icon *ngIf="licence.group == 'local'">location_city</mat-icon>
<mat-icon *ngIf="licence.group != 'local'">public_outlined</mat-icon>
{{ licence.priority+ '. ' +licence.name }}
<ng-container *ngIf="licence.group == 'local'">
<ng-container *ngIf="licence.group == 'local' && licence.exclusiveLock">
<span class="app-pipe"></span>
<mat-icon class="app-cursor-pointer" [matTooltip]="'item 1, item2, item 3'">lock</mat-icon>
<mat-icon class="app-cursor-pointer" [matTooltip]="'Počet čtenářů: ' +licence.readers + '| Maximální doba čtení: '+this.formatTime(licence.max)+' | Refresh interval: '+licence.refresh +' s'">lock</mat-icon>
</ng-container>
</mat-card-title>
<mat-card-subtitle *ngIf="licence.group == 'local'"><strong>{{ 'desc.localLicense' | translate }}</strong></mat-card-subtitle>
Expand Down
23 changes: 23 additions & 0 deletions src/app/pages/access/licenses/licenses.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export class LicensesComponent implements OnInit {
});
}


private sortLicenses() {
this.licenses.sort((a: License, b: License) => {
return a.priority - b.priority;
Expand Down Expand Up @@ -206,4 +207,26 @@ export class LicensesComponent implements OnInit {
}
}

formatTime(seconds: number): string {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const remainingSeconds = seconds % 60;

const hoursStr = hours === 1 ? '1 hodina' : `${hours} hodiny`;
const minutesStr = minutes === 1 ? '1 minuta' : `${minutes} minuty`;
const secondsStr = remainingSeconds === 1 ? '1 sekunda' : `${remainingSeconds} sekundy`;

const timeComponents = [];
if (hours > 0) {
timeComponents.push(hoursStr);
}
if (minutes > 0) {
timeComponents.push(minutesStr);
}
timeComponents.push(secondsStr);

return timeComponents.join(' a ');
}


}
6 changes: 4 additions & 2 deletions src/assets/i18n/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
},
"cdk": {
"title": "ČDK",
"icon":"settings_ethernet",
"desc": "Nastavení zapojených knihoven",
"proxy": {
"title": "Proxy - Zapojené knihovny",
"icon": "hub"
Expand Down Expand Up @@ -1149,8 +1151,8 @@
"listOfSets": "Seznam setů",
"implicitSet": "Implicitní set",
"turnOnTheLock": "Zapnout zámek",
"maximumReadingTime": "Maximální doba čtení",
"refreshInterval": "Refresh interval",
"maximumReadingTime": "Maximální doba čtení (v sekundách)",
"refreshInterval": "Refresh interval (v sekundách)",
"numberOfReadersReadingConcurrently": "Počet souběžně čtoucích čtenářů",
"localLicense": "Lokální licence"
}
Expand Down
6 changes: 4 additions & 2 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
},
"cdk": {
"title": "ČDK",
"icon":"settings_ethernet",
"desc": "Connected libraries settings",
"proxy": {
"title": "Proxy - connected libraries",
"icon": "hub"
Expand Down Expand Up @@ -1149,8 +1151,8 @@
"listOfSets": "List of sets",
"implicitSet": "Implicit set",
"turnOnTheLock": "Turn on the lock",
"maximumReadingTime": "Maximum reading time",
"refreshInterval": "Refresh interval",
"maximumReadingTime": "Maximum reading time (in seconds)",
"refreshInterval": "Refresh interval (in seconds)",
"numberOfReadersReadingConcurrently": "Number of readers reading concurrently",
"localLicense": "Local license"
}
Expand Down

0 comments on commit c2baa0e

Please sign in to comment.