48 changed files with 1404 additions and 92 deletions
@ -0,0 +1,30 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2022 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.sync.vc; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
|
||||
|
public class ClearRepositoryGitRequest extends VoidGitRequest { |
||||
|
|
||||
|
public ClearRepositoryGitRequest(TenantId tenantId) { |
||||
|
super(tenantId); |
||||
|
} |
||||
|
|
||||
|
public boolean requiresSettings() { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { Injectable } from '@angular/core'; |
||||
|
import { HttpClient } from '@angular/common/http'; |
||||
|
import { defaultHttpOptionsFromConfig, RequestConfig } from '@core/http/http-utils'; |
||||
|
import { Observable } from 'rxjs'; |
||||
|
import { BranchInfo, VersionCreateRequest, VersionCreationResult } from '@shared/models/vc.models'; |
||||
|
|
||||
|
@Injectable({ |
||||
|
providedIn: 'root' |
||||
|
}) |
||||
|
export class EntitiesVersionControlService { |
||||
|
|
||||
|
constructor( |
||||
|
private http: HttpClient |
||||
|
) { |
||||
|
} |
||||
|
|
||||
|
public listBranches(config?: RequestConfig): Observable<Array<BranchInfo>> { |
||||
|
return this.http.get<Array<BranchInfo>>('/api/entities/vc/branches', defaultHttpOptionsFromConfig(config)); |
||||
|
} |
||||
|
|
||||
|
public saveEntitiesVersion(request: VersionCreateRequest, config?: RequestConfig): Observable<VersionCreationResult> { |
||||
|
return this.http.post<VersionCreationResult>('/api/entities/vc/version', request, defaultHttpOptionsFromConfig(config)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2022 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<section style="min-width: 400px;"> |
||||
|
<mat-toolbar color="primary"> |
||||
|
<h2>{{ (createResult ? 'version-control.entity-version-exported' : 'version-control.export-entity-version') | translate }}</h2> |
||||
|
<span fxFlex></span> |
||||
|
<button mat-button mat-icon-button |
||||
|
(click)="cancel()" |
||||
|
type="button"> |
||||
|
<mat-icon class="material-icons">close</mat-icon> |
||||
|
</button> |
||||
|
</mat-toolbar> |
||||
|
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async"> |
||||
|
</mat-progress-bar> |
||||
|
<div mat-dialog-content> |
||||
|
<form *ngIf="!createResult" [formGroup]="exportFormGroup"> |
||||
|
<fieldset [disabled]="isLoading$ | async"> |
||||
|
<div fxFlex fxLayout="column"> |
||||
|
<tb-branch-autocomplete |
||||
|
required |
||||
|
formControlName="branch"> |
||||
|
</tb-branch-autocomplete> |
||||
|
<mat-form-field class="mat-block" fxFlex> |
||||
|
<mat-label translate>version-control.version-name</mat-label> |
||||
|
<input required matInput formControlName="versionName"> |
||||
|
<mat-error *ngIf="exportFormGroup.get('versionName').hasError('required')"> |
||||
|
{{ 'version-control.version-name-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-checkbox formControlName="saveRelations" style="margin-bottom: 16px;"> |
||||
|
{{ 'version-control.export-entity-relations' | translate }} |
||||
|
</mat-checkbox> |
||||
|
</div> |
||||
|
</fieldset> |
||||
|
</form> |
||||
|
<div *ngIf="createResult" fxFlex fxLayout="column" fxLayoutAlign="center"> |
||||
|
<div [innerHTML]="createResultMessage"></div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div *ngIf="!createResult" mat-dialog-actions fxLayoutAlign="end center"> |
||||
|
<button mat-button color="primary" |
||||
|
type="button" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="cancel()" cdkFocusInitial> |
||||
|
{{ 'action.cancel' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
type="button" |
||||
|
(click)="export()" |
||||
|
[disabled]="(isLoading$ | async) || exportFormGroup.invalid || !exportFormGroup.dirty"> |
||||
|
{{ 'action.export' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
<div *ngIf="createResult" mat-dialog-actions fxLayoutAlign="end center"> |
||||
|
<button mat-button color="primary" |
||||
|
type="button" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="cancel()" cdkFocusInitial> |
||||
|
{{ 'action.close' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
</section> |
||||
@ -0,0 +1,105 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { Component, Inject, OnInit, SkipSelf } from '@angular/core'; |
||||
|
import { ErrorStateMatcher } from '@angular/material/core'; |
||||
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms'; |
||||
|
import { Router } from '@angular/router'; |
||||
|
import { DialogComponent } from '@app/shared/components/dialog.component'; |
||||
|
import { EntityId } from '@shared/models/id/entity-id'; |
||||
|
import { |
||||
|
SingleEntityVersionCreateRequest, |
||||
|
VersionCreateRequestType, |
||||
|
VersionCreationResult |
||||
|
} from '@shared/models/vc.models'; |
||||
|
import { EntitiesVersionControlService } from '@core/http/entities-version-control.service'; |
||||
|
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; |
||||
|
import { TranslateService } from '@ngx-translate/core'; |
||||
|
|
||||
|
export interface VcEntityExportDialogData { |
||||
|
entityId: EntityId; |
||||
|
} |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-vc-entity-export-dialog', |
||||
|
templateUrl: './vc-entity-export-dialog.component.html', |
||||
|
providers: [{provide: ErrorStateMatcher, useExisting: VcEntityExportDialogComponent}], |
||||
|
styleUrls: [] |
||||
|
}) |
||||
|
export class VcEntityExportDialogComponent extends DialogComponent<VcEntityExportDialogComponent> |
||||
|
implements OnInit, ErrorStateMatcher { |
||||
|
|
||||
|
exportFormGroup: FormGroup; |
||||
|
|
||||
|
submitted = false; |
||||
|
|
||||
|
createResult: VersionCreationResult; |
||||
|
|
||||
|
createResultMessage: SafeHtml; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected router: Router, |
||||
|
@Inject(MAT_DIALOG_DATA) public data: VcEntityExportDialogData, |
||||
|
@SkipSelf() private errorStateMatcher: ErrorStateMatcher, |
||||
|
public dialogRef: MatDialogRef<VcEntityExportDialogComponent>, |
||||
|
private entitiesVersionControlService: EntitiesVersionControlService, |
||||
|
private translate: TranslateService, |
||||
|
private domSanitizer: DomSanitizer, |
||||
|
private fb: FormBuilder) { |
||||
|
super(store, router, dialogRef); |
||||
|
|
||||
|
this.exportFormGroup = this.fb.group({ |
||||
|
branch: [null, [Validators.required]], |
||||
|
versionName: [null, [Validators.required]], |
||||
|
saveRelations: [false, []] |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
} |
||||
|
|
||||
|
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { |
||||
|
const originalErrorState = this.errorStateMatcher.isErrorState(control, form); |
||||
|
const customErrorState = !!(control && control.invalid && this.submitted); |
||||
|
return originalErrorState || customErrorState; |
||||
|
} |
||||
|
|
||||
|
cancel(): void { |
||||
|
this.dialogRef.close(); |
||||
|
} |
||||
|
|
||||
|
export(): void { |
||||
|
this.submitted = true; |
||||
|
const request: SingleEntityVersionCreateRequest = { |
||||
|
entityId: this.data.entityId, |
||||
|
branch: this.exportFormGroup.get('branch').value, |
||||
|
versionName: this.exportFormGroup.get('versionName').value, |
||||
|
config: { |
||||
|
saveRelations: this.exportFormGroup.get('saveRelations').value |
||||
|
}, |
||||
|
type: VersionCreateRequestType.SINGLE_ENTITY |
||||
|
}; |
||||
|
this.entitiesVersionControlService.saveEntitiesVersion(request).subscribe((result) => { |
||||
|
this.createResult = result; |
||||
|
const message = this.translate.instant('version-control.export-entity-version-result-message', |
||||
|
{name: result.version.name, commitId: result.version.id}); |
||||
|
this.createResultMessage = this.domSanitizer.bypassSecurityTrustHtml(message); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,110 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2022 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<div> |
||||
|
<mat-card class="settings-card"> |
||||
|
<mat-card-title> |
||||
|
<div fxLayout="row"> |
||||
|
<span class="mat-headline" translate>admin.git-repository-settings</span> |
||||
|
<span fxFlex></span> |
||||
|
<div tb-help="versionControlSettings"></div> |
||||
|
</div> |
||||
|
</mat-card-title> |
||||
|
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async"> |
||||
|
</mat-progress-bar> |
||||
|
<div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div> |
||||
|
<mat-card-content style="padding-top: 16px;"> |
||||
|
<form [formGroup]="versionControlSettingsForm" #formDirective="ngForm" (ngSubmit)="save()"> |
||||
|
<fieldset [disabled]="isLoading$ | async"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>admin.repository-url</mat-label> |
||||
|
<input matInput required formControlName="repositoryUri"> |
||||
|
<mat-error translate *ngIf="versionControlSettingsForm.get('repositoryUri').hasError('required')"> |
||||
|
admin.repository-url-required |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>admin.default-branch</mat-label> |
||||
|
<input matInput formControlName="defaultBranch"> |
||||
|
</mat-form-field> |
||||
|
<fieldset [disabled]="isLoading$ | async" class="fields-group"> |
||||
|
<legend class="group-title" translate>admin.authentication-settings</legend> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>admin.auth-method</mat-label> |
||||
|
<mat-select required formControlName="authMethod"> |
||||
|
<mat-option *ngFor="let method of versionControlAuthMethods" [value]="method"> |
||||
|
{{versionControlAuthMethodTranslations.get(method) | translate}} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
</mat-form-field> |
||||
|
<section [fxShow]="versionControlSettingsForm.get('authMethod').value === versionControlAuthMethod.USERNAME_PASSWORD" fxLayout="column"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>common.username</mat-label> |
||||
|
<input matInput formControlName="username" placeholder="{{ 'common.enter-username' | translate }}" |
||||
|
autocomplete="new-username"/> |
||||
|
</mat-form-field> |
||||
|
<mat-checkbox *ngIf="showChangePassword" (change)="changePasswordChanged()" |
||||
|
[(ngModel)]="changePassword" [ngModelOptions]="{ standalone: true }" style="padding-bottom: 16px;"> |
||||
|
{{ 'admin.change-password-access-token' | translate }} |
||||
|
</mat-checkbox> |
||||
|
<mat-form-field class="mat-block" *ngIf="changePassword || !showChangePassword"> |
||||
|
<mat-label translate>admin.password-access-token</mat-label> |
||||
|
<input matInput formControlName="password" type="password" |
||||
|
placeholder="{{ 'common.enter-password' | translate }}" autocomplete="new-password"/> |
||||
|
<tb-toggle-password matSuffix></tb-toggle-password> |
||||
|
</mat-form-field> |
||||
|
</section> |
||||
|
<section [fxShow]="versionControlSettingsForm.get('authMethod').value === versionControlAuthMethod.PRIVATE_KEY" fxLayout="column"> |
||||
|
<tb-file-input style="margin-bottom: 16px;" |
||||
|
[existingFileName]="versionControlSettingsForm.get('privateKeyFileName').value" |
||||
|
required |
||||
|
formControlName="privateKey" |
||||
|
dropLabel="{{ 'admin.drop-private-key-file-or' | translate }}" |
||||
|
[label]="'admin.private-key' | translate" |
||||
|
(fileNameChanged)="versionControlSettingsForm.get('privateKeyFileName').patchValue($event)"> |
||||
|
</tb-file-input> |
||||
|
<mat-checkbox *ngIf="showChangePrivateKeyPassword" (change)="changePrivateKeyPasswordChanged()" |
||||
|
[(ngModel)]="changePrivateKeyPassword" [ngModelOptions]="{ standalone: true }" style="padding-bottom: 16px;"> |
||||
|
{{ 'admin.change-passphrase' | translate }} |
||||
|
</mat-checkbox> |
||||
|
<mat-form-field class="mat-block" *ngIf="changePrivateKeyPassword || !showChangePrivateKeyPassword"> |
||||
|
<mat-label translate>admin.passphrase</mat-label> |
||||
|
<input matInput formControlName="privateKeyPassword" type="password" |
||||
|
placeholder="{{ 'admin.enter-passphrase' | translate }}" autocomplete="new-password"/> |
||||
|
<tb-toggle-password matSuffix></tb-toggle-password> |
||||
|
</mat-form-field> |
||||
|
</section> |
||||
|
</fieldset> |
||||
|
<div fxLayout="row" fxLayoutAlign="end center" fxLayout.xs="column" fxLayoutAlign.xs="end" fxLayoutGap="16px"> |
||||
|
<button mat-raised-button color="warn" type="button" [fxShow]="settings !== null" |
||||
|
[disabled]="(isLoading$ | async)" (click)="delete(formDirective)"> |
||||
|
{{'action.delete' | translate}} |
||||
|
</button> |
||||
|
<span fxFlex></span> |
||||
|
<button mat-raised-button type="button" |
||||
|
[disabled]="(isLoading$ | async) || versionControlSettingsForm.invalid" (click)="checkAccess()"> |
||||
|
{{'admin.check-access' | translate}} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" [disabled]="(isLoading$ | async) || versionControlSettingsForm.invalid || !versionControlSettingsForm.dirty" |
||||
|
type="submit">{{'action.save' | translate}} |
||||
|
</button> |
||||
|
</div> |
||||
|
</fieldset> |
||||
|
</form> |
||||
|
</mat-card-content> |
||||
|
</mat-card> |
||||
|
</div> |
||||
@ -0,0 +1,33 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2022 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
:host { |
||||
|
.fields-group { |
||||
|
padding: 0 16px 8px; |
||||
|
margin-bottom: 10px; |
||||
|
border: 1px groove rgba(0, 0, 0, .25); |
||||
|
border-radius: 4px; |
||||
|
|
||||
|
legend { |
||||
|
color: rgba(0, 0, 0, .7); |
||||
|
width: fit-content; |
||||
|
} |
||||
|
|
||||
|
legend + * { |
||||
|
display: block; |
||||
|
margin-top: 16px; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,198 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { Component, OnInit } from '@angular/core'; |
||||
|
import { PageComponent } from '@shared/components/page.component'; |
||||
|
import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard'; |
||||
|
import { FormBuilder, FormGroup, FormGroupDirective, Validators } from '@angular/forms'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { AdminService } from '@core/http/admin.service'; |
||||
|
import { |
||||
|
EntitiesVersionControlSettings, |
||||
|
VersionControlAuthMethod, |
||||
|
versionControlAuthMethodTranslationMap |
||||
|
} from '@shared/models/settings.models'; |
||||
|
import { ActionNotificationShow } from '@core/notification/notification.actions'; |
||||
|
import { TranslateService } from '@ngx-translate/core'; |
||||
|
import { isNotEmptyStr } from '@core/utils'; |
||||
|
import { DialogService } from '@core/services/dialog.service'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-version-control-settings', |
||||
|
templateUrl: './version-control-settings.component.html', |
||||
|
styleUrls: ['./version-control-settings.component.scss', './settings-card.scss'] |
||||
|
}) |
||||
|
export class VersionControlSettingsComponent extends PageComponent implements OnInit, HasConfirmForm { |
||||
|
|
||||
|
versionControlSettingsForm: FormGroup; |
||||
|
settings: EntitiesVersionControlSettings = null; |
||||
|
|
||||
|
versionControlAuthMethod = VersionControlAuthMethod; |
||||
|
versionControlAuthMethods = Object.values(VersionControlAuthMethod); |
||||
|
versionControlAuthMethodTranslations = versionControlAuthMethodTranslationMap; |
||||
|
|
||||
|
showChangePassword = false; |
||||
|
changePassword = false; |
||||
|
|
||||
|
showChangePrivateKeyPassword = false; |
||||
|
changePrivateKeyPassword = false; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
private adminService: AdminService, |
||||
|
private dialogService: DialogService, |
||||
|
private translate: TranslateService, |
||||
|
public fb: FormBuilder) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
ngOnInit() { |
||||
|
this.versionControlSettingsForm = this.fb.group({ |
||||
|
repositoryUri: [null, [Validators.required]], |
||||
|
defaultBranch: [null, []], |
||||
|
authMethod: [VersionControlAuthMethod.USERNAME_PASSWORD, [Validators.required]], |
||||
|
username: [null, []], |
||||
|
password: [null, []], |
||||
|
privateKeyFileName: [null, [Validators.required]], |
||||
|
privateKey: [null, []], |
||||
|
privateKeyPassword: [null, []] |
||||
|
}); |
||||
|
this.updateValidators(false); |
||||
|
this.versionControlSettingsForm.get('authMethod').valueChanges.subscribe(() => { |
||||
|
this.updateValidators(true); |
||||
|
}); |
||||
|
this.versionControlSettingsForm.get('privateKeyFileName').valueChanges.subscribe(() => { |
||||
|
this.updateValidators(false); |
||||
|
}); |
||||
|
this.adminService.getEntitiesVersionControlSettings({ignoreErrors: true}).subscribe( |
||||
|
(settings) => { |
||||
|
this.settings = settings; |
||||
|
if (this.settings.authMethod === VersionControlAuthMethod.USERNAME_PASSWORD) { |
||||
|
this.showChangePassword = true; |
||||
|
} else { |
||||
|
this.showChangePrivateKeyPassword = true; |
||||
|
} |
||||
|
this.versionControlSettingsForm.reset(this.settings); |
||||
|
this.updateValidators(false); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
checkAccess(): void { |
||||
|
const settings: EntitiesVersionControlSettings = this.versionControlSettingsForm.value; |
||||
|
this.adminService.checkVersionControlAccess(settings).subscribe(() => { |
||||
|
this.store.dispatch(new ActionNotificationShow({ message: this.translate.instant('admin.check-vc-access-success'), |
||||
|
type: 'success' })); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
save(): void { |
||||
|
const settings: EntitiesVersionControlSettings = this.versionControlSettingsForm.value; |
||||
|
this.adminService.saveEntitiesVersionControlSettings(settings).subscribe( |
||||
|
(savedSettings) => { |
||||
|
this.settings = savedSettings; |
||||
|
if (this.settings.authMethod === VersionControlAuthMethod.USERNAME_PASSWORD) { |
||||
|
this.showChangePassword = true; |
||||
|
this.changePassword = false; |
||||
|
} else { |
||||
|
this.showChangePrivateKeyPassword = true; |
||||
|
this.changePrivateKeyPassword = false; |
||||
|
} |
||||
|
this.versionControlSettingsForm.reset(this.settings); |
||||
|
this.updateValidators(false); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
delete(formDirective: FormGroupDirective): void { |
||||
|
this.dialogService.confirm( |
||||
|
this.translate.instant('admin.delete-git-settings-title', ), |
||||
|
this.translate.instant('admin.delete-git-settings-text'), null, |
||||
|
this.translate.instant('action.delete') |
||||
|
).subscribe((data) => { |
||||
|
if (data) { |
||||
|
this.adminService.deleteEntitiesVersionControlSettings().subscribe( |
||||
|
() => { |
||||
|
this.settings = null; |
||||
|
this.showChangePassword = false; |
||||
|
this.changePassword = false; |
||||
|
this.showChangePrivateKeyPassword = false; |
||||
|
this.changePrivateKeyPassword = false; |
||||
|
formDirective.resetForm(); |
||||
|
this.versionControlSettingsForm.reset({ authMethod: VersionControlAuthMethod.USERNAME_PASSWORD }); |
||||
|
this.updateValidators(false); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
confirmForm(): FormGroup { |
||||
|
return this.versionControlSettingsForm; |
||||
|
} |
||||
|
|
||||
|
changePasswordChanged() { |
||||
|
if (this.changePassword) { |
||||
|
this.versionControlSettingsForm.get('password').patchValue(''); |
||||
|
this.versionControlSettingsForm.get('password').markAsDirty(); |
||||
|
} |
||||
|
this.updateValidators(false); |
||||
|
} |
||||
|
|
||||
|
changePrivateKeyPasswordChanged() { |
||||
|
if (this.changePrivateKeyPassword) { |
||||
|
this.versionControlSettingsForm.get('privateKeyPassword').patchValue(''); |
||||
|
this.versionControlSettingsForm.get('privateKeyPassword').markAsDirty(); |
||||
|
} |
||||
|
this.updateValidators(false); |
||||
|
} |
||||
|
|
||||
|
updateValidators(emitEvent?: boolean): void { |
||||
|
const authMethod: VersionControlAuthMethod = this.versionControlSettingsForm.get('authMethod').value; |
||||
|
const privateKeyFileName: string = this.versionControlSettingsForm.get('privateKeyFileName').value; |
||||
|
if (authMethod === VersionControlAuthMethod.USERNAME_PASSWORD) { |
||||
|
this.versionControlSettingsForm.get('username').enable({emitEvent}); |
||||
|
if (this.changePassword || !this.showChangePassword) { |
||||
|
this.versionControlSettingsForm.get('password').enable({emitEvent}); |
||||
|
} else { |
||||
|
this.versionControlSettingsForm.get('password').disable({emitEvent}); |
||||
|
} |
||||
|
this.versionControlSettingsForm.get('privateKeyFileName').disable({emitEvent}); |
||||
|
this.versionControlSettingsForm.get('privateKey').disable({emitEvent}); |
||||
|
this.versionControlSettingsForm.get('privateKeyPassword').disable({emitEvent}); |
||||
|
} else { |
||||
|
this.versionControlSettingsForm.get('username').disable({emitEvent}); |
||||
|
this.versionControlSettingsForm.get('password').disable({emitEvent}); |
||||
|
this.versionControlSettingsForm.get('privateKeyFileName').enable({emitEvent}); |
||||
|
this.versionControlSettingsForm.get('privateKey').enable({emitEvent}); |
||||
|
if (this.changePrivateKeyPassword || !this.showChangePrivateKeyPassword) { |
||||
|
this.versionControlSettingsForm.get('privateKeyPassword').enable({emitEvent}); |
||||
|
} else { |
||||
|
this.versionControlSettingsForm.get('privateKeyPassword').disable({emitEvent}); |
||||
|
} |
||||
|
if (isNotEmptyStr(privateKeyFileName)) { |
||||
|
this.versionControlSettingsForm.get('privateKey').clearValidators(); |
||||
|
} else { |
||||
|
this.versionControlSettingsForm.get('privateKey').setValidators([Validators.required]); |
||||
|
} |
||||
|
} |
||||
|
this.versionControlSettingsForm.get('username').updateValueAndValidity({emitEvent: false}); |
||||
|
this.versionControlSettingsForm.get('password').updateValueAndValidity({emitEvent: false}); |
||||
|
this.versionControlSettingsForm.get('privateKeyFileName').updateValueAndValidity({emitEvent: false}); |
||||
|
this.versionControlSettingsForm.get('privateKey').updateValueAndValidity({emitEvent: false}); |
||||
|
this.versionControlSettingsForm.get('privateKeyPassword').updateValueAndValidity({emitEvent: false}); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2022 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<mat-form-field [formGroup]="branchFormGroup" class="mat-block"> |
||||
|
<mat-label>{{ 'version-control.branch' | translate }}</mat-label> |
||||
|
<input matInput type="text" placeholder="{{ 'version-control.select-branch' | translate }}" |
||||
|
#branchInput |
||||
|
formControlName="branch" |
||||
|
(focusin)="onFocus()" |
||||
|
[required]="required" |
||||
|
[matAutocomplete]="subTypeAutocomplete"> |
||||
|
<button *ngIf="branchFormGroup.get('branch').value && !disabled" |
||||
|
type="button" |
||||
|
matSuffix mat-button mat-icon-button aria-label="Clear" |
||||
|
(click)="clear()"> |
||||
|
<mat-icon class="material-icons">close</mat-icon> |
||||
|
</button> |
||||
|
<mat-autocomplete |
||||
|
class="tb-autocomplete" |
||||
|
#subTypeAutocomplete="matAutocomplete" |
||||
|
[displayWith]="displayBranchFn"> |
||||
|
<mat-option *ngFor="let branch of filteredBranches | async" [value]="branch"> |
||||
|
<span [innerHTML]="branch | highlight:searchText"></span> |
||||
|
</mat-option> |
||||
|
</mat-autocomplete> |
||||
|
<mat-error *ngIf="branchFormGroup.get('branch').hasError('required')"> |
||||
|
{{ 'version-control.branch-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
@ -0,0 +1,199 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnInit, ViewChild } from '@angular/core'; |
||||
|
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms'; |
||||
|
import { Observable, of } from 'rxjs'; |
||||
|
import { |
||||
|
catchError, |
||||
|
debounceTime, |
||||
|
distinctUntilChanged, |
||||
|
map, |
||||
|
publishReplay, |
||||
|
refCount, |
||||
|
switchMap, |
||||
|
tap |
||||
|
} from 'rxjs/operators'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@app/core/core.state'; |
||||
|
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
||||
|
import { BranchInfo } from '@shared/models/vc.models'; |
||||
|
import { EntitiesVersionControlService } from '@core/http/entities-version-control.service'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-branch-autocomplete', |
||||
|
templateUrl: './branch-autocomplete.component.html', |
||||
|
styleUrls: [], |
||||
|
providers: [{ |
||||
|
provide: NG_VALUE_ACCESSOR, |
||||
|
useExisting: forwardRef(() => BranchAutocompleteComponent), |
||||
|
multi: true |
||||
|
}] |
||||
|
}) |
||||
|
export class BranchAutocompleteComponent implements ControlValueAccessor, OnInit, AfterViewInit { |
||||
|
|
||||
|
branchFormGroup: FormGroup; |
||||
|
|
||||
|
modelValue: string | null; |
||||
|
|
||||
|
private requiredValue: boolean; |
||||
|
|
||||
|
get required(): boolean { |
||||
|
return this.requiredValue; |
||||
|
} |
||||
|
|
||||
|
@Input() |
||||
|
set required(value: boolean) { |
||||
|
this.requiredValue = coerceBooleanProperty(value); |
||||
|
} |
||||
|
|
||||
|
@Input() |
||||
|
disabled: boolean; |
||||
|
|
||||
|
@Input() |
||||
|
selectDefaultBranch = true; |
||||
|
|
||||
|
@ViewChild('branchInput', {static: true}) branchInput: ElementRef; |
||||
|
|
||||
|
filteredBranches: Observable<Array<string>>; |
||||
|
|
||||
|
branches: Observable<Array<BranchInfo>>; |
||||
|
|
||||
|
searchText = ''; |
||||
|
|
||||
|
private dirty = false; |
||||
|
|
||||
|
private propagateChange = (v: any) => { }; |
||||
|
|
||||
|
constructor(private store: Store<AppState>, |
||||
|
private entitiesVersionControlService: EntitiesVersionControlService, |
||||
|
private fb: FormBuilder) { |
||||
|
this.branchFormGroup = this.fb.group({ |
||||
|
branch: [null, []] |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
registerOnChange(fn: any): void { |
||||
|
this.propagateChange = fn; |
||||
|
} |
||||
|
|
||||
|
registerOnTouched(fn: any): void { |
||||
|
} |
||||
|
|
||||
|
ngOnInit() { |
||||
|
|
||||
|
this.branches = null; |
||||
|
this.filteredBranches = this.branchFormGroup.get('branch').valueChanges |
||||
|
.pipe( |
||||
|
debounceTime(150), |
||||
|
distinctUntilChanged(), |
||||
|
tap(value => { |
||||
|
this.updateView(value); |
||||
|
}), |
||||
|
map(value => value ? value : ''), |
||||
|
switchMap(branch => this.fetchBranches(branch)) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
ngAfterViewInit(): void { |
||||
|
} |
||||
|
|
||||
|
setDisabledState(isDisabled: boolean): void { |
||||
|
this.disabled = isDisabled; |
||||
|
if (this.disabled) { |
||||
|
this.branchFormGroup.disable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.branchFormGroup.enable({emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
selectDefaultBranchIfNeeded(): void { |
||||
|
if (this.selectDefaultBranch && !this.modelValue) { |
||||
|
this.getBranches().subscribe( |
||||
|
(data) => { |
||||
|
if (data && data.length) { |
||||
|
const defaultBranch = data.find(branch => branch.default); |
||||
|
if (defaultBranch) { |
||||
|
this.modelValue = defaultBranch.name; |
||||
|
this.branchFormGroup.get('branch').patchValue(this.modelValue, {emitEvent: false}); |
||||
|
this.propagateChange(this.modelValue); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
writeValue(value: string | null): void { |
||||
|
this.searchText = ''; |
||||
|
this.modelValue = value; |
||||
|
if (value != null) { |
||||
|
this.branchFormGroup.get('branch').patchValue(value, {emitEvent: false}); |
||||
|
} else { |
||||
|
this.branchFormGroup.get('branch').patchValue('', {emitEvent: false}); |
||||
|
this.selectDefaultBranchIfNeeded(); |
||||
|
} |
||||
|
this.dirty = true; |
||||
|
} |
||||
|
|
||||
|
onFocus() { |
||||
|
if (this.dirty) { |
||||
|
this.branchFormGroup.get('branch').updateValueAndValidity({onlySelf: true, emitEvent: true}); |
||||
|
this.dirty = false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
updateView(value: string | null) { |
||||
|
if (this.modelValue !== value) { |
||||
|
this.modelValue = value; |
||||
|
this.propagateChange(this.modelValue); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
displayBranchFn(branch?: string): string | undefined { |
||||
|
return branch ? branch : undefined; |
||||
|
} |
||||
|
|
||||
|
fetchBranches(searchText?: string): Observable<Array<string>> { |
||||
|
this.searchText = searchText; |
||||
|
return this.getBranches().pipe( |
||||
|
map(branches => branches.map(branch => branch.name).filter(branchName => { |
||||
|
return searchText ? branchName.toUpperCase().startsWith(searchText.toUpperCase()) : true; |
||||
|
})) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
getBranches(): Observable<Array<BranchInfo>> { |
||||
|
if (!this.branches) { |
||||
|
const branchesObservable = this.entitiesVersionControlService.listBranches({ignoreLoading: true, ignoreErrors: true}); |
||||
|
this.branches = branchesObservable.pipe( |
||||
|
catchError(() => of([] as Array<BranchInfo>)), |
||||
|
publishReplay(1), |
||||
|
refCount() |
||||
|
); |
||||
|
} |
||||
|
return this.branches; |
||||
|
} |
||||
|
|
||||
|
clear() { |
||||
|
this.branchFormGroup.get('branch').patchValue(null, {emitEvent: true}); |
||||
|
setTimeout(() => { |
||||
|
this.branchInput.nativeElement.blur(); |
||||
|
this.branchInput.nativeElement.focus(); |
||||
|
}, 0); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,55 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { EntityId } from '@shared/models/id/entity-id'; |
||||
|
|
||||
|
export interface VersionCreateConfig { |
||||
|
saveRelations: boolean; |
||||
|
} |
||||
|
|
||||
|
export enum VersionCreateRequestType { |
||||
|
SINGLE_ENTITY = 'SINGLE_ENTITY', |
||||
|
COMPLEX = 'COMPLEX' |
||||
|
} |
||||
|
|
||||
|
export interface VersionCreateRequest { |
||||
|
versionName: string; |
||||
|
branch: string; |
||||
|
type: VersionCreateRequestType; |
||||
|
} |
||||
|
|
||||
|
export interface SingleEntityVersionCreateRequest extends VersionCreateRequest { |
||||
|
entityId: EntityId; |
||||
|
config: VersionCreateConfig; |
||||
|
type: VersionCreateRequestType.SINGLE_ENTITY; |
||||
|
} |
||||
|
|
||||
|
export interface BranchInfo { |
||||
|
name: string; |
||||
|
default: boolean; |
||||
|
} |
||||
|
|
||||
|
export interface EntityVersion { |
||||
|
id: string; |
||||
|
name: string; |
||||
|
} |
||||
|
|
||||
|
export interface VersionCreationResult { |
||||
|
version: EntityVersion; |
||||
|
added: number; |
||||
|
modified: number; |
||||
|
removed: number; |
||||
|
} |
||||
Loading…
Reference in new issue