Skip to content

Commit 8d2e729

Browse files
clear code and fix white labeling bugs
1 parent cda0d73 commit 8d2e729

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

application/src/main/java/org/thingsboard/server/controller/WhiteLabelController.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
import com.fasterxml.jackson.databind.JsonNode;
55
import com.google.common.base.Charsets;
6-
import freemarker.template.Configuration;
6+
import io.bit3.jsass.Compiler;
7+
import io.bit3.jsass.Options;
8+
import io.bit3.jsass.Output;
9+
import io.bit3.jsass.OutputStyle;
10+
import io.bit3.jsass.importer.Import;
711
import lombok.RequiredArgsConstructor;
812
import org.springframework.beans.factory.annotation.Autowired;
913
import org.springframework.core.io.Resource;
@@ -19,25 +23,19 @@
1923
import org.thingsboard.server.common.data.whitelabel.PaletteSettings;
2024
import org.thingsboard.server.dao.settings.AdminSettingsService;
2125
import org.thingsboard.server.queue.util.TbCoreComponent;
22-
import io.bit3.jsass.Compiler;
23-
import io.bit3.jsass.Options;
24-
import io.bit3.jsass.Output;
25-
import io.bit3.jsass.OutputStyle;
26-
import io.bit3.jsass.importer.Import;
2726

2827
import javax.annotation.PostConstruct;
2928
import java.net.URI;
30-
import java.util.*;
29+
import java.util.Collections;
30+
import java.util.HashMap;
31+
import java.util.Map;
3132

3233
@RequiredArgsConstructor
3334
@RestController
3435
@TbCoreComponent
3536
@RequestMapping("/api")
3637
public class WhiteLabelController extends BaseController{
3738

38-
@Autowired
39-
private Configuration freemarkerConfig;
40-
4139
@Autowired
4240
private AdminSettingsService adminSettingsService;
4341

@@ -82,7 +80,7 @@ private void initCompiler() throws Exception {
8280
} else if (fileName != null) {
8381
URI scssFileUri = scssResource.getURI();
8482
Import scssImport = new Import(scssFileUri, scssFileUri, scssContent);
85-
String path = fileName.substring(0, fileName.length() - ".scss".length());
83+
String path = fileName.substring(0, fileName.length() - SCSS_EXTENSION.length());
8684
this.importMap.put(path, scssImport);
8785
}
8886
}

ui-ngx/src/app/core/services/whitelabel-utils.service.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {LocalStorageService} from "@core/local-storage/local-storage.service";
2323
import {AdminService} from "@core/http/admin.service";
2424
import {DOCUMENT} from "@angular/common";
2525
import {WhiteLabelService} from "@core/http/white-label.service";
26-
import {WhiteLabeling} from "@shared/models/settings.models";
26+
import {Palette, WhiteLabeling} from "@shared/models/settings.models";
2727
import {whiteLabeling as wl} from "@global/white-labeling";
2828
import {ActionSettingsChangeLanguage} from "@core/settings/settings.actions";
2929
import {select, Store} from "@ngrx/store";
@@ -44,8 +44,6 @@ export class WhitelabelUtilsService {
4444

4545
appThemeCss: String;
4646

47-
// tempAppThemeCss: String;
48-
4947
loginThemeCssElm: any;
5048

5149
appThemeCssElm: any;
@@ -91,6 +89,9 @@ export class WhitelabelUtilsService {
9189
setup():Observable<WhiteLabeling>{
9290
return this.whiteLabelService.getWhiteLabel().pipe(
9391
map((whiteLabel)=>{
92+
if (!whiteLabel) {
93+
whiteLabel = this.getDefaultWhiteLabeling();
94+
}
9495
this.whiteLabeling = this.mergeWithConst(whiteLabel);
9596
this.process(true);
9697
return whiteLabel;
@@ -112,6 +113,26 @@ export class WhitelabelUtilsService {
112113
);
113114
}
114115

116+
getDefaultWhiteLabeling(): WhiteLabeling {
117+
return {
118+
appTitle: null,
119+
customCss: null,
120+
enableHelpLinks: false,
121+
faviconUrl: null,
122+
helpLinkBaseUrl: null,
123+
logoImageHeight: null,
124+
logoImageUrl: null,
125+
paletteSettings: {
126+
primaryPalette: null,
127+
accentPalette: null
128+
},
129+
platformName: null,
130+
platformVersion: null,
131+
showNameVersion: false,
132+
whiteLabelingEnabled: true
133+
}
134+
}
135+
115136
setupLoginTheme():Observable<void> {
116137
this.addLoginTheme();
117138
return this.whiteLabelService.getLoginTheme(this.whiteLabeling).pipe(

ui-ngx/src/app/modules/home/pages/admin/white-labeling.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { AppState } from '@core/core.state';
44
import { PageComponent } from '@shared/components/page.component';
55
import { Router } from '@angular/router';
66
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
7-
import {WhiteLabeling} from '@shared/models/settings.models';
8-
import { WhiteLabelService } from '@core/http/white-label.service';
97
import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard';
10-
import {WhitelabelUtilsService} from "@core/services/whitelabel-utils.service";
11-
import {MaterialColorItem, materialColors} from '@app/shared/models/material.models';
8+
import { MaterialColorItem } from '@app/shared/models/material.models';
9+
import { WhiteLabeling } from '@shared/models/settings.models';
10+
import { WhiteLabelService } from '@core/http/white-label.service';
11+
import { WhitelabelUtilsService } from "@core/services/whitelabel-utils.service";
1212

1313
@Component({
1414
selector: 'tb-white-labeling',
@@ -39,6 +39,9 @@ export class WhiteLabelingComponent extends PageComponent implements OnInit, Has
3939
this.buildWhitelabelingSettingsForm();
4040
this.whiteLabelService.getWhiteLabel().subscribe(
4141
(whiteLabel) => {
42+
if(!whiteLabel) {
43+
whiteLabel = this.whiteLabelUtilsService.getDefaultWhiteLabeling();
44+
}
4245
this.whiteLabeling = whiteLabel;
4346
this.whiteLabelingSettings.reset(this.whiteLabeling);
4447
}

0 commit comments

Comments
 (0)