Boris Voropaev 2023-12-12 17:44:35 +03:00
commit f0ecad8e94
17 changed files with 173 additions and 45 deletions

View File

@ -11,6 +11,7 @@ import {CompaniesModule} from "@app/_modules/companies/companies.module";
import {AdministrateSitePagesComponent} from "@app/_modules/administration/site-pages/administrate-site-pages.component";
import {PagesModule} from "@app/_modules/pages/pages.module";
import {WidjetModule} from "@app/_modules/widjet/widjet.module";
import {AdministrateLicenceComponent} from "@app/_modules/administration/licence/administrate-licence.component";
type PathMatch = "full" | "prefix" | undefined;
const routes = [
@ -28,12 +29,13 @@ const routes = [
PagesModule,
WidjetModule,
],
declarations: [
AdministrationPageComponent,
AdministrateCompanyComponent,
AdministrateCommitteeComponent,
AdministrateSitePagesComponent
],
declarations: [
AdministrationPageComponent,
AdministrateCompanyComponent,
AdministrateCommitteeComponent,
AdministrateSitePagesComponent,
AdministrateLicenceComponent
],
exports: [
RouterModule
]

View File

@ -0,0 +1,12 @@
<table class="default">
<tr><td class="caption">Состояние лицензии</td><td class="value">{{licence?.state?.title || 'Не найдено'}}</td></tr>
<tr><td class="caption">Номер лицензии</td><td class="value">{{number || '-'}}</td></tr>
<tr><td class="caption">Продукт</td><td class="value">{{product?.title || '-'}}</td></tr>
<tr><td class="caption">Доменное имя</td><td class="value">{{licence?.domain || '-'}}</td></tr>
<tr><td class="caption">Дата начала действия</td><td class="value">{{licence?.activeSince | date: 'dd.MM.yyyy'}}</td></tr>
<tr><td class="caption">Дата окончания действия</td><td class="value">{{licence?.activeTill | date: 'dd.MM.yyyy'}}</td></tr>
</table>
<h3>Доступные опции</h3>
<ul *ngIf="options?.length"><li *ngFor="let option of options">{{option.title}}</li></ul>
<p *ngIf="!options?.length">отсутствуют</p>

View File

@ -0,0 +1,26 @@
import {Component} from '@angular/core';
import {LicenceService} from "@app/_services/licence.service";
@Component({
selector: 'administrate-licence',
templateUrl: 'administrate-licence.component.html',
styleUrls: ['administrate-licence.component.scss']
})
export class AdministrateLicenceComponent {
constructor(private licenceService: LicenceService) {
}
get number() {
return this.licenceService.number;
}
get licence() {
return this.licenceService.licence;
}
get product() {
return this.licence?.product?.data;
}
get options() {
return this.licence?.options?.data;
}
}

View File

@ -3,14 +3,14 @@
<h2>Панель управления</h2>
</div>
<!-- <div class="tabs default">
<div class="tabs default">
<button type="button" *ngFor="let tab of tabs" [class.active]="tab.active" routerLink="/administrate/{{tab.name}}">{{tab.title}}</button>
</div> -->
</div>
<div [ngSwitch]="tab.name">
<administrate-company *ngSwitchCase="'company'" [companyId]="'main'"></administrate-company>
<administrate-committee *ngSwitchCase="'committee'"></administrate-committee>
<administrate-site-pages *ngSwitchCase="'site-pages'"></administrate-site-pages>
<administrate-licence *ngSwitchCase="'licence'"></administrate-licence>
<p *ngSwitchDefault>Страница не найдена</p>
</div>
</div>

View File

@ -35,7 +35,7 @@ export class AdministrationPageComponent {
makeTabs() {
//this.tabs = [{name: 'company', title: 'Структура ФАУ «ФЦС»'}, {name: 'committee', title: 'Структура ТК 465'}];
//if (this.authService.isSuperAdmin) this.tabs.push({name: 'site-pages', title: 'Структура сайта'});
this.tabs = [{name: 'site-pages', title: 'Структура сайта'}];
this.tabs = [{name: 'site-pages', title: 'Структура сайта'}, {name: 'licence', title: 'Данные о лицензии'}];
this.switchTab(this.route.snapshot.paramMap.get('tab'));
}

View File

@ -1,14 +1,13 @@
<div class="site-admin-control">
<div class="site-admin-control-toggle" (click)="toggle()">
Показать скрытые
<switch [val]="showDeleted"></switch>
</div>
<div class="site-admin-page-block">
<div class="site-admin-company">
<ico ico="cloud_24" class="page-lable" color="#FFF"></ico>
<span>Сайт компании</span>
</div>
<ico ico="home_plus_24" class="page-control" (click)="addLocale()"></ico>
</div>
</div>
<pages-tree></pages-tree>
<ng-container *ngIf="licenceService.isActive">
<div class="site-admin-control">
<button (click)="addLocale()" class="outline">Добавить языковую версию</button>
<span class="site-admin-control-toggle" (click)="toggle()">
Показать удаленные
<switch [val]="showDeleted"></switch>
</span>
</div>
<pages-tree></pages-tree>
</ng-container>
<ng-container *ngIf="!licenceService.isActive">
<p>Лицензия не активна. Перейдите в раздел <a routerLink="/administrate/licence">Данные о лицензии</a></p>
</ng-container>

View File

@ -1,6 +1,7 @@
import {Component} from '@angular/core';
import {PagesService} from "@app/_services/pages.service";
import { FormsService } from '@app/_services';
import {LicenceService} from "@app/_services/licence.service";
@Component({
selector: 'administrate-site-pages',
@ -8,9 +9,17 @@ import { FormsService } from '@app/_services';
styleUrls: ['administrate-site-pages.component.scss']
})
export class AdministrateSitePagesComponent {
constructor(private pagesService: PagesService, private formsService: FormsService) {
constructor(private pagesService: PagesService, private formsService: FormsService, public licenceService: LicenceService) {
}
get isLicenceActive() {
return this.licenceService.isActive;
}
get isMultilang() {
return this.isLicenceActive && this.licenceService.hasOption('multilang');
}
get showDeleted() {
return this.pagesService.showDeleted;
}
@ -23,12 +32,8 @@ export class AdministrateSitePagesComponent {
}
addLocale() {
this.formsService.createModel('localePage', null, 'pages-tree-root');
this.pagesService.root({include:'children'}).subscribe(
res => {
this.pagesService.rootPages = res
}
)
if (this.isMultilang) this.formsService.createModel('localePage', null, 'pages-tree-root');
else alert('Отсутствует необходимая опция');
}
toggle() {

View File

@ -9,7 +9,7 @@
<div class="layout-corral jumbotron-edit-field-row">
<div class="switch-host" (click)="toggleEditMode()">
Режим редактирования
<switch [val]="editMode"></switch>
</div>
<switch [val]="editMode"></switch>
</div>
</div>
</div>
</div>

View File

@ -1,5 +1,6 @@
import { Component } from '@angular/core';
import { PagesService } from '@app/_services/pages.service';
import {LicenceService} from "@app/_services/licence.service";
@Component({
selector: 'jumbotron',
@ -9,7 +10,7 @@ import { PagesService } from '@app/_services/pages.service';
export class JumbotronComponent {
constructor(
private pagesService: PagesService,
private pagesService: PagesService
){}
get currentPage(){
@ -28,7 +29,7 @@ export class JumbotronComponent {
height = 150;
pictURL = this.currentPage?.picture?.data.links.open;
}
return {
'background-image' : `url(${pictURL})`||'none',
'height': (pictURL?400:height) + 'px'
@ -39,15 +40,15 @@ export class JumbotronComponent {
return { color: this.currentPage?.picture?'var(--white)':'var(--second-act)'}
}
get editable(){
get editable() {
return this.currentPage?.permissions?.edit || this.currentPage?.permissions?.anything;
}
get editMode(){
get editMode() {
return this.pagesService.editMode;
}
toggleEditMode(){
toggleEditMode() {
this.pagesService.editMode = !this.pagesService.editMode;
}

View File

@ -6,13 +6,14 @@ import {Router} from "@angular/router";
import {environment} from '@environments/environment';
import {OauthToken, User} from '@app/_models';
import {UsersService} from "@app/_services/users.service";
import {LicenceService} from "@app/_services/licence.service";
@Injectable({providedIn: 'root'})
export class AuthenticationService {
public tokenSubject = new BehaviorSubject(JSON.parse(localStorage.getItem('oauthToken')));
public userSubject = new BehaviorSubject(null);
constructor(private http: HttpClient, private router: Router, private usersService: UsersService) {
constructor(private http: HttpClient, private router: Router, private usersService: UsersService, private licenceService: LicenceService) {
}
get token(): OauthToken {
@ -77,6 +78,7 @@ export class AuthenticationService {
getCurrentUser(params?: any) {
if (this.isLoggedIn) this.usersService.me(params).subscribe(res => {
this.user = res.data;
this.licenceService.check();
});
}

View File

@ -0,0 +1,71 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {BehaviorSubject, Observable} from "rxjs";
import {environment} from '@environments/environment';
@Injectable({providedIn: 'root'})
export class LicenceService {
private host = 'https://services.testnir.ru';
private productName = 'cms';
public licenceSubject = new BehaviorSubject<any>(null);
constructor(private http: HttpClient) {
}
get number() {
return environment.licence;
}
get licence() {
return this.licenceSubject.value;
}
set licence(value: any) {
this.licenceSubject.next(value);
}
get product() {
return this.licence?.product?.data;
}
get options() {
return this.licence?.options?.data;
}
get isActive() {
return this.isActiveState && this.isCorrectProduct;
}
get isActiveState() {
return this.licence?.state?.name === 'active';
}
get isCorrectProduct() {
return this.product?.name === this.productName;
}
public check() {
this.fetch().subscribe(res => {
this.licence = res?.data;
});
}
fetch(): Observable<any> {
let include = ['product', 'options'];
return this.http.get(`${this.host}/api/licences/check/${this.number}`, {params: {include: include.join(',')}});
}
public hasOption(name: string): boolean {
return !!this.options?.filter(item => {return item.name === name}).length;
}
public checkEditAvailability(page?: any) {
if (!this.isActive) return this.error('Licence not active');
if ((page?.type?.name === 'registry') && !this.hasOption('registries')) return this.error('Registries option required');
if ((page?.type?.name === 'publications') && !this.hasOption('publications')) return this.error('Publications option required');
return null;
}
public error(msg: string) {
return msg;
}
}

View File

@ -2,6 +2,7 @@ import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {environment} from '@environments/environment';
import {Observable, BehaviorSubject} from "rxjs";
import {LicenceService} from "@app/_services/licence.service";
@Injectable({providedIn: 'root'})
@ -13,13 +14,11 @@ export class PagesService {
public showDeletedSubject = new BehaviorSubject<boolean>(false);
public menuSelectedLink: string;
constructor(private http: HttpClient) {
public rootPage = {link:'', slug:environment.defaultLocale};
constructor(private http: HttpClient, private licenceService: LicenceService) {
//this.find('/').subscribe(res => {this.rootPages = res.data});
}
rootPage={
link:'',
slug:environment.defaultLocale
}
get currentPage() {
return this.currentPageSubject.value;
@ -40,6 +39,13 @@ export class PagesService {
return this.editModeSubject.value;
}
set editMode(value: boolean) {
if (value) {
let error = this.licenceService.checkEditAvailability(this.currentPage);
if (error) {
alert(error);
return;
}
}
this.editModeSubject.next(value);
}

View File

@ -4,5 +4,6 @@ export const environment = {
clientId: 2,
clientSecret: 'uMYJ7jTYfSKst631D9gKlSwlNF0bWlcrR1d5mTKX',
project: null,
licence: '',
defaultLocale: 'ru'
};

View File

@ -8,6 +8,7 @@ export const environment = {
clientId: 2,
clientSecret: 'E4BoAclC9X3gre4Wr4XXmU3Y7sXTEtFSk3iCSkIm',
project: null,
licence: 'POUFLO4YW7SU',
defaultLocale: 'ru'
};

View File

@ -8,6 +8,7 @@ export const environment = {
clientId: 2,
clientSecret: 'E4BoAclC9X3gre4Wr4XXmU3Y7sXTEtFSk3iCSkIm',
project: 'vniigaz-v2',
licence: 'POUFLO4YW7SU',
defaultLocale: 'ru'
};

View File

@ -8,6 +8,7 @@ export const environment = {
clientId: 2,
clientSecret: 'hqhpnNTBrvqiv4o85ZNCewOO8n3Y2i9iaRYGfMnt',
project: null,
licence: '',
defaultLocale: 'ru'
};