75 changed files with 1763 additions and 648 deletions
@ -1,102 +0,0 @@ |
|||||
/** |
|
||||
* 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 lombok.RequiredArgsConstructor; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.cache.TbTransactionalCache; |
|
||||
import org.thingsboard.server.common.data.AdminSettings; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.data.sync.vc.EntitiesVersionControlSettings; |
|
||||
import org.thingsboard.server.common.data.sync.vc.VersionControlAuthMethod; |
|
||||
import org.thingsboard.server.dao.settings.AdminSettingsService; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Service |
|
||||
@TbCoreComponent |
|
||||
@RequiredArgsConstructor |
|
||||
public class DefaultTbVersionControlSettingsService implements TbVersionControlSettingsService { |
|
||||
|
|
||||
public static final String SETTINGS_KEY = "entitiesVersionControl"; |
|
||||
private final AdminSettingsService adminSettingsService; |
|
||||
private final TbTransactionalCache<TenantId, EntitiesVersionControlSettings> cache; |
|
||||
|
|
||||
@Override |
|
||||
public EntitiesVersionControlSettings restore(TenantId tenantId, EntitiesVersionControlSettings settings) { |
|
||||
EntitiesVersionControlSettings storedSettings = get(tenantId); |
|
||||
if (storedSettings != null) { |
|
||||
VersionControlAuthMethod authMethod = settings.getAuthMethod(); |
|
||||
if (VersionControlAuthMethod.USERNAME_PASSWORD.equals(authMethod) && settings.getPassword() == null) { |
|
||||
settings.setPassword(storedSettings.getPassword()); |
|
||||
} else if (VersionControlAuthMethod.PRIVATE_KEY.equals(authMethod) && settings.getPrivateKey() == null) { |
|
||||
settings.setPrivateKey(storedSettings.getPrivateKey()); |
|
||||
if (settings.getPrivateKeyPassword() == null) { |
|
||||
settings.setPrivateKeyPassword(storedSettings.getPrivateKeyPassword()); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return settings; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public EntitiesVersionControlSettings get(TenantId tenantId) { |
|
||||
EntitiesVersionControlSettings settings = cache.getAndPutInTransaction(tenantId, () -> { |
|
||||
AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(tenantId, SETTINGS_KEY); |
|
||||
if (adminSettings != null) { |
|
||||
try { |
|
||||
return JacksonUtil.convertValue(adminSettings.getJsonValue(), EntitiesVersionControlSettings.class); |
|
||||
} catch (Exception e) { |
|
||||
throw new RuntimeException("Failed to load version control settings!", e); |
|
||||
} |
|
||||
} |
|
||||
return null; |
|
||||
}, true); |
|
||||
if (settings != null) { |
|
||||
settings = new EntitiesVersionControlSettings(settings); |
|
||||
} |
|
||||
return settings; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public EntitiesVersionControlSettings save(TenantId tenantId, EntitiesVersionControlSettings versionControlSettings) { |
|
||||
AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(tenantId, SETTINGS_KEY); |
|
||||
if (adminSettings == null) { |
|
||||
adminSettings = new AdminSettings(); |
|
||||
adminSettings.setKey(SETTINGS_KEY); |
|
||||
adminSettings.setTenantId(tenantId); |
|
||||
} |
|
||||
adminSettings.setJsonValue(JacksonUtil.valueToTree(versionControlSettings)); |
|
||||
AdminSettings savedAdminSettings = adminSettingsService.saveAdminSettings(tenantId, adminSettings); |
|
||||
EntitiesVersionControlSettings savedVersionControlSettings; |
|
||||
try { |
|
||||
savedVersionControlSettings = JacksonUtil.convertValue(savedAdminSettings.getJsonValue(), EntitiesVersionControlSettings.class); |
|
||||
} catch (Exception e) { |
|
||||
throw new RuntimeException("Failed to load version control settings!", e); |
|
||||
} |
|
||||
//API calls to adminSettingsService are not in transaction, so we can simply evict the cache.
|
|
||||
cache.evict(tenantId); |
|
||||
return savedVersionControlSettings; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public boolean delete(TenantId tenantId) { |
|
||||
boolean result = adminSettingsService.deleteAdminSettings(tenantId, SETTINGS_KEY); |
|
||||
cache.evict(tenantId); |
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,80 @@ |
|||||
|
/** |
||||
|
* 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.common.util.JacksonUtil; |
||||
|
import org.thingsboard.server.cache.TbTransactionalCache; |
||||
|
import org.thingsboard.server.common.data.AdminSettings; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.dao.settings.AdminSettingsService; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
public abstract class TbAbstractVersionControlSettingsService<T extends Serializable> { |
||||
|
|
||||
|
private final String settingsKey; |
||||
|
private final AdminSettingsService adminSettingsService; |
||||
|
private final TbTransactionalCache<TenantId, T> cache; |
||||
|
private final Class<T> clazz; |
||||
|
|
||||
|
public TbAbstractVersionControlSettingsService(AdminSettingsService adminSettingsService, TbTransactionalCache<TenantId, T> cache, Class<T> clazz, String settingsKey) { |
||||
|
this.adminSettingsService = adminSettingsService; |
||||
|
this.cache = cache; |
||||
|
this.clazz = clazz; |
||||
|
this.settingsKey = settingsKey; |
||||
|
} |
||||
|
|
||||
|
public T get(TenantId tenantId) { |
||||
|
return cache.getAndPutInTransaction(tenantId, () -> { |
||||
|
AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(tenantId, settingsKey); |
||||
|
if (adminSettings != null) { |
||||
|
try { |
||||
|
return JacksonUtil.convertValue(adminSettings.getJsonValue(), clazz); |
||||
|
} catch (Exception e) { |
||||
|
throw new RuntimeException("Failed to load " + settingsKey + " settings!", e); |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
}, true); |
||||
|
} |
||||
|
|
||||
|
public T save(TenantId tenantId, T settings) { |
||||
|
AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(tenantId, settingsKey); |
||||
|
if (adminSettings == null) { |
||||
|
adminSettings = new AdminSettings(); |
||||
|
adminSettings.setKey(settingsKey); |
||||
|
adminSettings.setTenantId(tenantId); |
||||
|
} |
||||
|
adminSettings.setJsonValue(JacksonUtil.valueToTree(settings)); |
||||
|
AdminSettings savedAdminSettings = adminSettingsService.saveAdminSettings(tenantId, adminSettings); |
||||
|
T savedSettings; |
||||
|
try { |
||||
|
savedSettings = JacksonUtil.convertValue(savedAdminSettings.getJsonValue(), clazz); |
||||
|
} catch (Exception e) { |
||||
|
throw new RuntimeException("Failed to load auto commit settings!", e); |
||||
|
} |
||||
|
//API calls to adminSettingsService are not in transaction, so we can simply evict the cache.
|
||||
|
cache.evict(tenantId); |
||||
|
return savedSettings; |
||||
|
} |
||||
|
|
||||
|
public boolean delete(TenantId tenantId) { |
||||
|
boolean result = adminSettingsService.deleteAdminSettings(tenantId, settingsKey); |
||||
|
cache.evict(tenantId); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
/** |
||||
|
* 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.autocommit; |
||||
|
|
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.cache.TbTransactionalCache; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.sync.vc.AutoCommitSettings; |
||||
|
import org.thingsboard.server.dao.settings.AdminSettingsService; |
||||
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
||||
|
import org.thingsboard.server.service.sync.vc.TbAbstractVersionControlSettingsService; |
||||
|
|
||||
|
@Service |
||||
|
@TbCoreComponent |
||||
|
public class DefaultTbAutoCommitSettingsService extends TbAbstractVersionControlSettingsService<AutoCommitSettings> implements TbAutoCommitSettingsService { |
||||
|
|
||||
|
public static final String SETTINGS_KEY = "autoCommitSettings"; |
||||
|
|
||||
|
public DefaultTbAutoCommitSettingsService(AdminSettingsService adminSettingsService, TbTransactionalCache<TenantId, AutoCommitSettings> cache) { |
||||
|
super(adminSettingsService, cache, AutoCommitSettings.class, SETTINGS_KEY); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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.autocommit; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.sync.vc.AutoCommitSettings; |
||||
|
import org.thingsboard.server.common.data.sync.vc.RepositorySettings; |
||||
|
|
||||
|
public interface TbAutoCommitSettingsService { |
||||
|
|
||||
|
AutoCommitSettings get(TenantId tenantId); |
||||
|
|
||||
|
AutoCommitSettings save(TenantId tenantId, AutoCommitSettings settings); |
||||
|
|
||||
|
boolean delete(TenantId tenantId); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
/** |
||||
|
* 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.repository; |
||||
|
|
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.cache.TbTransactionalCache; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.sync.vc.RepositorySettings; |
||||
|
import org.thingsboard.server.common.data.sync.vc.RepositoryAuthMethod; |
||||
|
import org.thingsboard.server.dao.settings.AdminSettingsService; |
||||
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
||||
|
import org.thingsboard.server.service.sync.vc.TbAbstractVersionControlSettingsService; |
||||
|
|
||||
|
@Service |
||||
|
@TbCoreComponent |
||||
|
public class DefaultTbRepositorySettingsService extends TbAbstractVersionControlSettingsService<RepositorySettings> implements TbRepositorySettingsService { |
||||
|
|
||||
|
public static final String SETTINGS_KEY = "entitiesVersionControl"; |
||||
|
|
||||
|
public DefaultTbRepositorySettingsService(AdminSettingsService adminSettingsService, TbTransactionalCache<TenantId, RepositorySettings> cache) { |
||||
|
super(adminSettingsService, cache, RepositorySettings.class, SETTINGS_KEY); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public RepositorySettings restore(TenantId tenantId, RepositorySettings settings) { |
||||
|
RepositorySettings storedSettings = get(tenantId); |
||||
|
if (storedSettings != null) { |
||||
|
RepositoryAuthMethod authMethod = settings.getAuthMethod(); |
||||
|
if (RepositoryAuthMethod.USERNAME_PASSWORD.equals(authMethod) && settings.getPassword() == null) { |
||||
|
settings.setPassword(storedSettings.getPassword()); |
||||
|
} else if (RepositoryAuthMethod.PRIVATE_KEY.equals(authMethod) && settings.getPrivateKey() == null) { |
||||
|
settings.setPrivateKey(storedSettings.getPrivateKey()); |
||||
|
if (settings.getPrivateKeyPassword() == null) { |
||||
|
settings.setPrivateKeyPassword(storedSettings.getPrivateKeyPassword()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return settings; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public RepositorySettings get(TenantId tenantId) { |
||||
|
RepositorySettings settings = super.get(tenantId); |
||||
|
if (settings != null) { |
||||
|
settings = new RepositorySettings(settings); |
||||
|
} |
||||
|
return settings; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
/** |
||||
|
* 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.repository; |
||||
|
|
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
|
import org.springframework.cache.CacheManager; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.cache.CaffeineTbTransactionalCache; |
||||
|
import org.thingsboard.server.common.data.CacheConstants; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.sync.vc.RepositorySettings; |
||||
|
|
||||
|
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "caffeine", matchIfMissing = true) |
||||
|
@Service("RepositorySettingsCache") |
||||
|
public class RepositorySettingsCaffeineCache extends CaffeineTbTransactionalCache<TenantId, RepositorySettings> { |
||||
|
|
||||
|
public RepositorySettingsCaffeineCache(CacheManager cacheManager) { |
||||
|
super(cacheManager, CacheConstants.REPOSITORY_SETTINGS_CACHE); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
/** |
||||
|
* 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.repository; |
||||
|
|
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.cache.CacheSpecsMap; |
||||
|
import org.thingsboard.server.cache.RedisTbTransactionalCache; |
||||
|
import org.thingsboard.server.cache.TBRedisCacheConfiguration; |
||||
|
import org.thingsboard.server.cache.TbRedisSerializer; |
||||
|
import org.thingsboard.server.common.data.CacheConstants; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.sync.vc.RepositorySettings; |
||||
|
|
||||
|
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis") |
||||
|
@Service("RepositorySettingsCache") |
||||
|
public class RepositorySettingsRedisCache extends RedisTbTransactionalCache<TenantId, RepositorySettings> { |
||||
|
|
||||
|
public RepositorySettingsRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) { |
||||
|
super(CacheConstants.REPOSITORY_SETTINGS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbRedisSerializer<>()); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
/** |
||||
|
* 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.common.data.sync.vc; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.EntityType; |
||||
|
import org.thingsboard.server.common.data.sync.vc.request.create.AutoVersionCreateConfig; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
|
||||
|
public class AutoCommitSettings extends HashMap<EntityType, AutoVersionCreateConfig> { |
||||
|
|
||||
|
private static final long serialVersionUID = -5757067601838792059L; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
/** |
||||
|
* 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.common.data.sync.vc; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
|
||||
|
@Data |
||||
|
@AllArgsConstructor |
||||
|
@NoArgsConstructor |
||||
|
public class EntityDataInfo { |
||||
|
boolean hasRelations; |
||||
|
boolean hasAttributes; |
||||
|
} |
||||
@ -0,0 +1,125 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
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="auto-commit-settings settings-card"> |
||||
|
<mat-card-title> |
||||
|
<div fxLayout="row"> |
||||
|
<span class="mat-headline" translate>admin.auto-commit-settings</span> |
||||
|
<span fxFlex></span> |
||||
|
<div tb-help="autoCommitSettings"></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]="autoCommitSettingsForm" #formDirective="ngForm" (ngSubmit)="save()"> |
||||
|
<fieldset class="fields-group" [disabled]="isLoading$ | async"> |
||||
|
<legend class="group-title" translate>admin.auto-commit-entities</legend> |
||||
|
<div fxLayout="column"> |
||||
|
<div class="tb-control-list"> |
||||
|
<div *ngFor="let entityTypeFormGroup of entityTypesFormGroupArray(); trackBy: trackByEntityType; |
||||
|
let $index = index; last as isLast;" |
||||
|
fxLayout="row" fxLayoutAlign="start center" [ngStyle]="!isLast ? {paddingBottom: '8px'} : {}"> |
||||
|
<mat-expansion-panel class="entity-type-config" fxFlex [formGroup]="entityTypeFormGroup" [expanded]="entityTypesFormGroupExpanded(entityTypeFormGroup)"> |
||||
|
<mat-expansion-panel-header> |
||||
|
<div fxFlex fxLayout="row" fxLayoutAlign="start center"> |
||||
|
<mat-panel-title> |
||||
|
<div fxLayout="row" fxFlex fxLayoutAlign="start center"> |
||||
|
<div [innerHTML]="entityTypeText(entityTypeFormGroup)"></div> |
||||
|
</div> |
||||
|
</mat-panel-title> |
||||
|
<span fxFlex></span> |
||||
|
<button mat-icon-button style="min-width: 40px;" |
||||
|
type="button" |
||||
|
(click)="removeEntityType($index)" |
||||
|
matTooltip="{{ 'action.remove' | translate }}" |
||||
|
matTooltipPosition="above"> |
||||
|
<mat-icon>delete</mat-icon> |
||||
|
</button> |
||||
|
</div> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<div class="entity-type-config-content" fxLayout="column" fxLayoutGap="0.5em"> |
||||
|
<mat-divider></mat-divider> |
||||
|
<div fxLayout="column" fxLayout.gt-lg="row" fxLayoutGap.gt-lg="16px"> |
||||
|
<div fxLayout="row" fxLayoutGap="16px"> |
||||
|
<tb-entity-type-select |
||||
|
showLabel |
||||
|
formControlName="entityType" |
||||
|
required |
||||
|
[filterAllowedEntityTypes]="false" |
||||
|
[allowedEntityTypes]="allowedEntityTypes(entityTypeFormGroup)"> |
||||
|
</tb-entity-type-select> |
||||
|
<div formGroupName="config"> |
||||
|
<tb-branch-autocomplete |
||||
|
emptyPlaceholder="{{ 'version-control.default' | translate }}" |
||||
|
[selectDefaultBranch]="false" |
||||
|
formControlName="branch"> |
||||
|
</tb-branch-autocomplete> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="16px" formGroupName="config"> |
||||
|
<mat-checkbox formControlName="saveRelations"> |
||||
|
{{ 'version-control.export-entity-relations' | translate }} |
||||
|
</mat-checkbox> |
||||
|
<mat-checkbox formControlName="saveAttributes"> |
||||
|
{{ 'version-control.export-entity-attributes' | translate }} |
||||
|
</mat-checkbox> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div *ngIf="!entityTypesFormGroupArray().length"> |
||||
|
<span translate fxLayoutAlign="center center" |
||||
|
class="tb-prompt">admin.no-auto-commit-entities-prompt</span> |
||||
|
</div> |
||||
|
<div style="padding-top: 16px;" fxLayout="row"> |
||||
|
<button mat-raised-button color="primary" |
||||
|
type="button" |
||||
|
[disabled]="!addEnabled()" |
||||
|
(click)="addEntityType()"> |
||||
|
<span translate>version-control.add-entity-type</span> |
||||
|
</button> |
||||
|
<span fxFlex></span> |
||||
|
<button mat-raised-button color="primary" |
||||
|
type="button" |
||||
|
[disabled]="!entityTypesFormGroupArray().length" |
||||
|
(click)="removeAll()"> |
||||
|
<span translate>version-control.remove-all</span> |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
</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 color="primary" [disabled]="(isLoading$ | async) || autoCommitSettingsForm.invalid || !autoCommitSettingsForm.dirty" |
||||
|
type="submit">{{'action.save' | translate}} |
||||
|
</button> |
||||
|
</div> |
||||
|
</form> |
||||
|
</mat-card-content> |
||||
|
</mat-card> |
||||
|
</div> |
||||
@ -0,0 +1,74 @@ |
|||||
|
/** |
||||
|
* 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 { |
||||
|
mat-card.auto-commit-settings { |
||||
|
margin: 8px; |
||||
|
.mat-divider { |
||||
|
position: relative; |
||||
|
} |
||||
|
} |
||||
|
.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; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.tb-control-list { |
||||
|
overflow-y: auto; |
||||
|
max-height: 600px; |
||||
|
} |
||||
|
|
||||
|
.tb-prompt { |
||||
|
margin: 30px 0; |
||||
|
} |
||||
|
|
||||
|
mat-expansion-panel.entity-type-config { |
||||
|
box-shadow: none; |
||||
|
border: 1px groove rgba(0, 0, 0, .25); |
||||
|
.mat-expansion-panel-header { |
||||
|
padding: 0 24px 0 8px; |
||||
|
height: 48px; |
||||
|
} |
||||
|
.entity-type-config-content { |
||||
|
padding: 0 8px 8px; |
||||
|
tb-branch-autocomplete { |
||||
|
min-width: 200px; |
||||
|
max-width: 200px; |
||||
|
display: block; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
:host ::ng-deep { |
||||
|
.mat-expansion-panel.entity-type-config { |
||||
|
.mat-expansion-panel-body { |
||||
|
padding: 0; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,210 @@ |
|||||
|
///
|
||||
|
/// 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 { AbstractControl, FormArray, 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 { AutoCommitSettings, AutoVersionCreateConfig } from '@shared/models/settings.models'; |
||||
|
import { TranslateService } from '@ngx-translate/core'; |
||||
|
import { DialogService } from '@core/services/dialog.service'; |
||||
|
import { catchError, mergeMap } from 'rxjs/operators'; |
||||
|
import { of } from 'rxjs'; |
||||
|
import { EntityTypeVersionCreateConfig, exportableEntityTypes } from '@shared/models/vc.models'; |
||||
|
import { EntityType, entityTypeTranslations } from '@shared/models/entity-type.models'; |
||||
|
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-auto-commit-settings', |
||||
|
templateUrl: './auto-commit-settings.component.html', |
||||
|
styleUrls: ['./auto-commit-settings.component.scss', './../../pages/admin/settings-card.scss'] |
||||
|
}) |
||||
|
export class AutoCommitSettingsComponent extends PageComponent implements OnInit { |
||||
|
|
||||
|
autoCommitSettingsForm: FormGroup; |
||||
|
settings: AutoCommitSettings = null; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
private adminService: AdminService, |
||||
|
private dialogService: DialogService, |
||||
|
private sanitizer: DomSanitizer, |
||||
|
private translate: TranslateService, |
||||
|
public fb: FormBuilder) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
ngOnInit() { |
||||
|
this.autoCommitSettingsForm = this.fb.group({ |
||||
|
entityTypes: this.fb.array([], []) |
||||
|
}); |
||||
|
this.adminService.autoCommitSettingsExists().pipe( |
||||
|
catchError(() => of(false)), |
||||
|
mergeMap((hasAutoCommitSettings) => { |
||||
|
if (hasAutoCommitSettings) { |
||||
|
return this.adminService.getAutoCommitSettings({ignoreErrors: true}).pipe( |
||||
|
catchError(() => of(null)) |
||||
|
); |
||||
|
} else { |
||||
|
return of(null); |
||||
|
} |
||||
|
}) |
||||
|
).subscribe( |
||||
|
(settings) => { |
||||
|
this.settings = settings; |
||||
|
this.autoCommitSettingsForm.setControl('entityTypes', |
||||
|
this.prepareEntityTypesFormArray(settings), {emitEvent: false}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
entityTypesFormGroupArray(): FormGroup[] { |
||||
|
return (this.autoCommitSettingsForm.get('entityTypes') as FormArray).controls as FormGroup[]; |
||||
|
} |
||||
|
|
||||
|
entityTypesFormGroupExpanded(entityTypeControl: AbstractControl): boolean { |
||||
|
return !!(entityTypeControl as any).expanded; |
||||
|
} |
||||
|
|
||||
|
public trackByEntityType(index: number, entityTypeControl: AbstractControl): any { |
||||
|
return entityTypeControl; |
||||
|
} |
||||
|
|
||||
|
public removeEntityType(index: number) { |
||||
|
(this.autoCommitSettingsForm.get('entityTypes') as FormArray).removeAt(index); |
||||
|
this.autoCommitSettingsForm.markAsDirty(); |
||||
|
} |
||||
|
|
||||
|
public addEnabled(): boolean { |
||||
|
const entityTypesArray = this.autoCommitSettingsForm.get('entityTypes') as FormArray; |
||||
|
return entityTypesArray.length < exportableEntityTypes.length; |
||||
|
} |
||||
|
|
||||
|
public addEntityType() { |
||||
|
const entityTypesArray = this.autoCommitSettingsForm.get('entityTypes') as FormArray; |
||||
|
const config: AutoVersionCreateConfig = { |
||||
|
branch: null, |
||||
|
saveRelations: false, |
||||
|
saveAttributes: false |
||||
|
}; |
||||
|
const allowed = this.allowedEntityTypes(); |
||||
|
let entityType: EntityType = null; |
||||
|
if (allowed.length) { |
||||
|
entityType = allowed[0]; |
||||
|
} |
||||
|
const entityTypeControl = this.createEntityTypeControl(entityType, config); |
||||
|
(entityTypeControl as any).expanded = true; |
||||
|
entityTypesArray.push(entityTypeControl); |
||||
|
this.autoCommitSettingsForm.updateValueAndValidity(); |
||||
|
this.autoCommitSettingsForm.markAsDirty(); |
||||
|
} |
||||
|
|
||||
|
public removeAll() { |
||||
|
const entityTypesArray = this.autoCommitSettingsForm.get('entityTypes') as FormArray; |
||||
|
entityTypesArray.clear(); |
||||
|
this.autoCommitSettingsForm.updateValueAndValidity(); |
||||
|
this.autoCommitSettingsForm.markAsDirty(); |
||||
|
} |
||||
|
|
||||
|
entityTypeText(entityTypeControl: AbstractControl): SafeHtml { |
||||
|
const entityType: EntityType = entityTypeControl.get('entityType').value; |
||||
|
const config: AutoVersionCreateConfig = entityTypeControl.get('config').value; |
||||
|
let message = entityType ? this.translate.instant(entityTypeTranslations.get(entityType).typePlural) : 'Undefined'; |
||||
|
let branchName; |
||||
|
if (config.branch) { |
||||
|
branchName = config.branch; |
||||
|
} else { |
||||
|
branchName = this.translate.instant('version-control.default'); |
||||
|
} |
||||
|
message += ` (<small>${this.translate.instant('version-control.auto-commit-to-branch', {branch: branchName})}</small>)`; |
||||
|
return this.sanitizer.bypassSecurityTrustHtml(message); |
||||
|
} |
||||
|
|
||||
|
allowedEntityTypes(entityTypeControl?: AbstractControl): Array<EntityType> { |
||||
|
let res = [...exportableEntityTypes]; |
||||
|
const currentEntityType: EntityType = entityTypeControl?.get('entityType')?.value; |
||||
|
const value: [{entityType: string, config: EntityTypeVersionCreateConfig}] = |
||||
|
this.autoCommitSettingsForm.get('entityTypes').value || []; |
||||
|
const usedEntityTypes = value.map(val => val.entityType).filter(val => val); |
||||
|
res = res.filter(entityType => !usedEntityTypes.includes(entityType) || entityType === currentEntityType); |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
save(): void { |
||||
|
const value: [{entityType: string, config: AutoVersionCreateConfig}] = |
||||
|
this.autoCommitSettingsForm.get('entityTypes').value || []; |
||||
|
const settings: AutoCommitSettings = {}; |
||||
|
if (value && value.length) { |
||||
|
value.forEach((val) => { |
||||
|
settings[val.entityType] = val.config; |
||||
|
}); |
||||
|
} |
||||
|
this.adminService.saveAutoCommitSettings(settings).subscribe( |
||||
|
(savedSettings) => { |
||||
|
this.settings = savedSettings; |
||||
|
this.autoCommitSettingsForm.setControl('entityTypes', |
||||
|
this.prepareEntityTypesFormArray(savedSettings), {emitEvent: false}); |
||||
|
this.autoCommitSettingsForm.markAsPristine(); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
delete(formDirective: FormGroupDirective): void { |
||||
|
this.dialogService.confirm( |
||||
|
this.translate.instant('admin.delete-auto-commit-settings-title', ), |
||||
|
this.translate.instant('admin.delete-auto-commit-settings-text'), null, |
||||
|
this.translate.instant('action.delete') |
||||
|
).subscribe((data) => { |
||||
|
if (data) { |
||||
|
this.adminService.deleteAutoCommitSettings().subscribe( |
||||
|
() => { |
||||
|
this.settings = null; |
||||
|
this.autoCommitSettingsForm.setControl('entityTypes', |
||||
|
this.prepareEntityTypesFormArray(this.settings), {emitEvent: false}); |
||||
|
this.autoCommitSettingsForm.markAsPristine(); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private prepareEntityTypesFormArray(settings: AutoCommitSettings | null): FormArray { |
||||
|
const entityTypesControls: Array<AbstractControl> = []; |
||||
|
if (settings) { |
||||
|
for (const entityType of Object.keys(settings)) { |
||||
|
const config = settings[entityType]; |
||||
|
entityTypesControls.push(this.createEntityTypeControl(entityType as EntityType, config)); |
||||
|
} |
||||
|
} |
||||
|
return this.fb.array(entityTypesControls); |
||||
|
} |
||||
|
|
||||
|
private createEntityTypeControl(entityType: EntityType, config: AutoVersionCreateConfig): AbstractControl { |
||||
|
const entityTypeControl = this.fb.group( |
||||
|
{ |
||||
|
entityType: [entityType, [Validators.required]], |
||||
|
config: this.fb.group({ |
||||
|
branch: [config.branch, []], |
||||
|
saveRelations: [config.saveRelations, []], |
||||
|
saveAttributes: [config.saveAttributes, []] |
||||
|
}) |
||||
|
} |
||||
|
); |
||||
|
return entityTypeControl; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
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: 300px;"> |
||||
|
<form [formGroup]="confirmFormGroup" style="padding-top: 16px;"> |
||||
|
<fieldset [disabled]="(isLoading$ | async)"> |
||||
|
<div style="user-select: none;" [innerHTML]="removeOtherEntitiesConfirmText"></div> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<input matInput formControlName="verification"/> |
||||
|
</mat-form-field> |
||||
|
</fieldset> |
||||
|
</form> |
||||
|
<div fxLayoutAlign="end center" fxLayoutGap="8px"> |
||||
|
<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)="confirm()" |
||||
|
[disabled]="(isLoading$ | async) || confirmFormGroup.invalid || confirmFormGroup.get('verification').value !== removeOtherEntitiesVerificationText"> |
||||
|
{{ 'action.confirm' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
</section> |
||||
@ -0,0 +1,66 @@ |
|||||
|
///
|
||||
|
/// 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, Input, OnInit } from '@angular/core'; |
||||
|
import { PageComponent } from '@shared/components/page.component'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { TranslateService } from '@ngx-translate/core'; |
||||
|
import { FormBuilder, FormGroup } from '@angular/forms'; |
||||
|
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-remove-other-entities-confirm', |
||||
|
templateUrl: './remove-other-entities-confirm.component.html', |
||||
|
styleUrls: [] |
||||
|
}) |
||||
|
export class RemoveOtherEntitiesConfirmComponent extends PageComponent implements OnInit { |
||||
|
|
||||
|
@Input() |
||||
|
onClose: (result: boolean | null) => void; |
||||
|
|
||||
|
confirmFormGroup: FormGroup; |
||||
|
|
||||
|
removeOtherEntitiesConfirmText: SafeHtml; |
||||
|
|
||||
|
removeOtherEntitiesVerificationText = 'remove other entities'; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
private translate: TranslateService, |
||||
|
private sanitizer: DomSanitizer, |
||||
|
private fb: FormBuilder) { |
||||
|
super(store); |
||||
|
this.removeOtherEntitiesConfirmText = this.sanitizer.bypassSecurityTrustHtml(this.translate.instant('version-control.remove-other-entities-confirm-text')); |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.confirmFormGroup = this.fb.group({ |
||||
|
verification: [null, []] |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
cancel(): void { |
||||
|
if (this.onClose) { |
||||
|
this.onClose(null); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
confirm(): void { |
||||
|
if (this.onClose) { |
||||
|
this.onClose(true); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,216 @@ |
|||||
|
///
|
||||
|
/// 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, Input, OnInit } from '@angular/core'; |
||||
|
import { PageComponent } from '@shared/components/page.component'; |
||||
|
import { FormBuilder, FormGroup, FormGroupDirective, Validators } from '@angular/forms'; |
||||
|
import { select, Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { AdminService } from '@core/http/admin.service'; |
||||
|
import { |
||||
|
RepositorySettings, |
||||
|
RepositoryAuthMethod, |
||||
|
repositoryAuthMethodTranslationMap |
||||
|
} 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'; |
||||
|
import { ActionAuthUpdateHasRepository } from '@core/auth/auth.actions'; |
||||
|
import { selectHasRepository } from '@core/auth/auth.selectors'; |
||||
|
import { catchError, mergeMap, take } from 'rxjs/operators'; |
||||
|
import { of } from 'rxjs'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-repository-settings', |
||||
|
templateUrl: './repository-settings.component.html', |
||||
|
styleUrls: ['./repository-settings.component.scss', './../../pages/admin/settings-card.scss'] |
||||
|
}) |
||||
|
export class RepositorySettingsComponent extends PageComponent implements OnInit { |
||||
|
|
||||
|
@Input() |
||||
|
detailsMode = false; |
||||
|
|
||||
|
repositorySettingsForm: FormGroup; |
||||
|
settings: RepositorySettings = null; |
||||
|
|
||||
|
repositoryAuthMethod = RepositoryAuthMethod; |
||||
|
repositoryAuthMethods = Object.values(RepositoryAuthMethod); |
||||
|
repositoryAuthMethodTranslations = repositoryAuthMethodTranslationMap; |
||||
|
|
||||
|
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.repositorySettingsForm = this.fb.group({ |
||||
|
repositoryUri: [null, [Validators.required]], |
||||
|
defaultBranch: ['main', []], |
||||
|
authMethod: [RepositoryAuthMethod.USERNAME_PASSWORD, [Validators.required]], |
||||
|
username: [null, []], |
||||
|
password: [null, []], |
||||
|
privateKeyFileName: [null, [Validators.required]], |
||||
|
privateKey: [null, []], |
||||
|
privateKeyPassword: [null, []] |
||||
|
}); |
||||
|
this.updateValidators(false); |
||||
|
this.repositorySettingsForm.get('authMethod').valueChanges.subscribe(() => { |
||||
|
this.updateValidators(true); |
||||
|
}); |
||||
|
this.repositorySettingsForm.get('privateKeyFileName').valueChanges.subscribe(() => { |
||||
|
this.updateValidators(false); |
||||
|
}); |
||||
|
this.store.pipe( |
||||
|
select(selectHasRepository), |
||||
|
take(1), |
||||
|
mergeMap((hasRepository) => { |
||||
|
if (hasRepository) { |
||||
|
return this.adminService.getRepositorySettings({ignoreErrors: true}).pipe( |
||||
|
catchError(() => of(null)) |
||||
|
); |
||||
|
} else { |
||||
|
return of(null); |
||||
|
} |
||||
|
}) |
||||
|
).subscribe( |
||||
|
(settings) => { |
||||
|
this.settings = settings; |
||||
|
if (this.settings != null) { |
||||
|
if (this.settings.authMethod === RepositoryAuthMethod.USERNAME_PASSWORD) { |
||||
|
this.showChangePassword = true; |
||||
|
} else { |
||||
|
this.showChangePrivateKeyPassword = true; |
||||
|
} |
||||
|
this.repositorySettingsForm.reset(this.settings); |
||||
|
this.updateValidators(false); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
checkAccess(): void { |
||||
|
const settings: RepositorySettings = this.repositorySettingsForm.value; |
||||
|
this.adminService.checkRepositoryAccess(settings).subscribe(() => { |
||||
|
this.store.dispatch(new ActionNotificationShow({ message: this.translate.instant('admin.check-repository-access-success'), |
||||
|
type: 'success' })); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
save(): void { |
||||
|
const settings: RepositorySettings = this.repositorySettingsForm.value; |
||||
|
this.adminService.saveRepositorySettings(settings).subscribe( |
||||
|
(savedSettings) => { |
||||
|
this.settings = savedSettings; |
||||
|
if (this.settings.authMethod === RepositoryAuthMethod.USERNAME_PASSWORD) { |
||||
|
this.showChangePassword = true; |
||||
|
this.changePassword = false; |
||||
|
} else { |
||||
|
this.showChangePrivateKeyPassword = true; |
||||
|
this.changePrivateKeyPassword = false; |
||||
|
} |
||||
|
this.repositorySettingsForm.reset(this.settings); |
||||
|
this.updateValidators(false); |
||||
|
this.store.dispatch(new ActionAuthUpdateHasRepository({ hasRepository: true })); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
delete(formDirective: FormGroupDirective): void { |
||||
|
this.dialogService.confirm( |
||||
|
this.translate.instant('admin.delete-repository-settings-title', ), |
||||
|
this.translate.instant('admin.delete-repository-settings-text'), null, |
||||
|
this.translate.instant('action.delete') |
||||
|
).subscribe((data) => { |
||||
|
if (data) { |
||||
|
this.adminService.deleteRepositorySettings().subscribe( |
||||
|
() => { |
||||
|
this.settings = null; |
||||
|
this.showChangePassword = false; |
||||
|
this.changePassword = false; |
||||
|
this.showChangePrivateKeyPassword = false; |
||||
|
this.changePrivateKeyPassword = false; |
||||
|
formDirective.resetForm(); |
||||
|
this.repositorySettingsForm.reset({ defaultBranch: 'main', authMethod: RepositoryAuthMethod.USERNAME_PASSWORD }); |
||||
|
this.updateValidators(false); |
||||
|
this.store.dispatch(new ActionAuthUpdateHasRepository({ hasRepository: false })); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
changePasswordChanged() { |
||||
|
if (this.changePassword) { |
||||
|
this.repositorySettingsForm.get('password').patchValue(''); |
||||
|
this.repositorySettingsForm.get('password').markAsDirty(); |
||||
|
} |
||||
|
this.updateValidators(false); |
||||
|
} |
||||
|
|
||||
|
changePrivateKeyPasswordChanged() { |
||||
|
if (this.changePrivateKeyPassword) { |
||||
|
this.repositorySettingsForm.get('privateKeyPassword').patchValue(''); |
||||
|
this.repositorySettingsForm.get('privateKeyPassword').markAsDirty(); |
||||
|
} |
||||
|
this.updateValidators(false); |
||||
|
} |
||||
|
|
||||
|
updateValidators(emitEvent?: boolean): void { |
||||
|
const authMethod: RepositoryAuthMethod = this.repositorySettingsForm.get('authMethod').value; |
||||
|
const privateKeyFileName: string = this.repositorySettingsForm.get('privateKeyFileName').value; |
||||
|
if (authMethod === RepositoryAuthMethod.USERNAME_PASSWORD) { |
||||
|
this.repositorySettingsForm.get('username').enable({emitEvent}); |
||||
|
if (this.changePassword || !this.showChangePassword) { |
||||
|
this.repositorySettingsForm.get('password').enable({emitEvent}); |
||||
|
} else { |
||||
|
this.repositorySettingsForm.get('password').disable({emitEvent}); |
||||
|
} |
||||
|
this.repositorySettingsForm.get('privateKeyFileName').disable({emitEvent}); |
||||
|
this.repositorySettingsForm.get('privateKey').disable({emitEvent}); |
||||
|
this.repositorySettingsForm.get('privateKeyPassword').disable({emitEvent}); |
||||
|
} else { |
||||
|
this.repositorySettingsForm.get('username').disable({emitEvent}); |
||||
|
this.repositorySettingsForm.get('password').disable({emitEvent}); |
||||
|
this.repositorySettingsForm.get('privateKeyFileName').enable({emitEvent}); |
||||
|
this.repositorySettingsForm.get('privateKey').enable({emitEvent}); |
||||
|
if (this.changePrivateKeyPassword || !this.showChangePrivateKeyPassword) { |
||||
|
this.repositorySettingsForm.get('privateKeyPassword').enable({emitEvent}); |
||||
|
} else { |
||||
|
this.repositorySettingsForm.get('privateKeyPassword').disable({emitEvent}); |
||||
|
} |
||||
|
if (isNotEmptyStr(privateKeyFileName)) { |
||||
|
this.repositorySettingsForm.get('privateKey').clearValidators(); |
||||
|
} else { |
||||
|
this.repositorySettingsForm.get('privateKey').setValidators([Validators.required]); |
||||
|
} |
||||
|
} |
||||
|
this.repositorySettingsForm.get('username').updateValueAndValidity({emitEvent: false}); |
||||
|
this.repositorySettingsForm.get('password').updateValueAndValidity({emitEvent: false}); |
||||
|
this.repositorySettingsForm.get('privateKeyFileName').updateValueAndValidity({emitEvent: false}); |
||||
|
this.repositorySettingsForm.get('privateKey').updateValueAndValidity({emitEvent: false}); |
||||
|
this.repositorySettingsForm.get('privateKeyPassword').updateValueAndValidity({emitEvent: false}); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -1,218 +0,0 @@ |
|||||
///
|
|
||||
/// 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, Input, 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 { select, 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'; |
|
||||
import { ActionSettingsChangeLanguage } from '@core/settings/settings.actions'; |
|
||||
import { ActionAuthUpdateHasVersionControl } from '@core/auth/auth.actions'; |
|
||||
import { selectHasVersionControl } from '@core/auth/auth.selectors'; |
|
||||
import { catchError, mergeMap, take } from 'rxjs/operators'; |
|
||||
import { of } from 'rxjs'; |
|
||||
|
|
||||
@Component({ |
|
||||
selector: 'tb-version-control-settings', |
|
||||
templateUrl: './version-control-settings.component.html', |
|
||||
styleUrls: ['./version-control-settings.component.scss', './../../pages/admin/settings-card.scss'] |
|
||||
}) |
|
||||
export class VersionControlSettingsComponent extends PageComponent implements OnInit { |
|
||||
|
|
||||
@Input() |
|
||||
detailsMode = false; |
|
||||
|
|
||||
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: ['main', []], |
|
||||
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.store.pipe( |
|
||||
select(selectHasVersionControl), |
|
||||
take(1), |
|
||||
mergeMap((hasVersionControl) => { |
|
||||
if (hasVersionControl) { |
|
||||
return this.adminService.getEntitiesVersionControlSettings({ignoreErrors: true}).pipe( |
|
||||
catchError(() => of(null)) |
|
||||
); |
|
||||
} else { |
|
||||
return of(null); |
|
||||
} |
|
||||
}) |
|
||||
).subscribe( |
|
||||
(settings) => { |
|
||||
this.settings = settings; |
|
||||
if (this.settings != null) { |
|
||||
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); |
|
||||
this.store.dispatch(new ActionAuthUpdateHasVersionControl({ hasVersionControl: true })); |
|
||||
} |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
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({ defaultBranch: 'main', authMethod: VersionControlAuthMethod.USERNAME_PASSWORD }); |
|
||||
this.updateValidators(false); |
|
||||
this.store.dispatch(new ActionAuthUpdateHasVersionControl({ hasVersionControl: false })); |
|
||||
} |
|
||||
); |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
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,23 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
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. |
||||
|
|
||||
|
--> |
||||
|
<tb-repository-settings #repositorySettingsComponent |
||||
|
*ngIf="!(hasRepository$ | async); else autoCommitSettings"> |
||||
|
</tb-repository-settings> |
||||
|
<ng-template #autoCommitSettings> |
||||
|
<tb-auto-commit-settings #autoCommitSettingsComponent></tb-auto-commit-settings> |
||||
|
</ng-template> |
||||
@ -0,0 +1,51 @@ |
|||||
|
///
|
||||
|
/// 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, ViewChild } from '@angular/core'; |
||||
|
import { PageComponent } from '@shared/components/page.component'; |
||||
|
import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard'; |
||||
|
import { select, Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { FormGroup } from '@angular/forms'; |
||||
|
import { AutoCommitSettingsComponent } from '@home/components/vc/auto-commit-settings.component'; |
||||
|
import { selectHasRepository } from '@core/auth/auth.selectors'; |
||||
|
import { RepositorySettingsComponent } from '@home/components/vc/repository-settings.component'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-auto-commit-admin-settings', |
||||
|
templateUrl: './auto-commit-admin-settings.component.html', |
||||
|
styleUrls: [] |
||||
|
}) |
||||
|
export class AutoCommitAdminSettingsComponent extends PageComponent implements OnInit, HasConfirmForm { |
||||
|
|
||||
|
@ViewChild('repositorySettingsComponent', {static: false}) repositorySettingsComponent: RepositorySettingsComponent; |
||||
|
@ViewChild('autoCommitSettingsComponent', {static: false}) autoCommitSettingsComponent: AutoCommitSettingsComponent; |
||||
|
|
||||
|
hasRepository$ = this.store.pipe(select(selectHasRepository)); |
||||
|
|
||||
|
constructor(protected store: Store<AppState>) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
ngOnInit() { |
||||
|
} |
||||
|
|
||||
|
confirmForm(): FormGroup { |
||||
|
return this.repositorySettingsComponent ? |
||||
|
this.repositorySettingsComponent?.repositorySettingsForm : |
||||
|
this.autoCommitSettingsComponent?.autoCommitSettingsForm; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue