Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a theme model that inherits from a base class with serialization information. #5472

Merged
merged 71 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
9e015fc
work for #5094 Create a theme model that inherits from a base class w…
Jan 19, 2024
75420fc
Merge branch 'master' of github.com:surveyjs/survey-creator into issu…
Mar 13, 2024
87acfa7
work for #5094 Create a theme model that inherits from a base class w…
Mar 13, 2024
944cf56
work for #5161
Mar 14, 2024
55aa2d0
Remove the child tab from the root #5161
andrewtelnov Mar 14, 2024
ca36d37
work for #5094
Mar 13, 2024
ff9679b
Merge remote-tracking branch 'origin/issue/5161-PG-subgroup' into iss…
Mar 14, 2024
f77e03e
work for #5094
Mar 15, 2024
244e892
Merge branch 'master' of github.com:surveyjs/survey-creator into issu…
Mar 21, 2024
7d079a3
work for #5094
Mar 21, 2024
ee89d28
work for #5094
Mar 21, 2024
ac04ff1
work for #5094 Create a theme model that inherits from a base class w…
Mar 22, 2024
6480067
work for #5094 Create a theme model that inherits from a base class w…
Mar 29, 2024
96a60b1
Merge branch 'master' of github.com:surveyjs/survey-creator into issu…
Mar 29, 2024
f12b15e
work for #5094 Create a theme model that inherits from a base class w…
Apr 1, 2024
7ca9434
resolve https://github.com/surveyjs/service/issues/1792
Apr 4, 2024
0d9c2b1
work for #5094 Create a theme model that inherits from a base class w…
Apr 5, 2024
dd77f8b
work for #5094 Create a theme model that inherits from a base class w…
Apr 10, 2024
67bdc13
Merge branch 'master' of github.com:surveyjs/survey-creator into issu…
Apr 11, 2024
5431844
work for #5094 Create a theme model that inherits from a base class w…
Apr 11, 2024
6b7291e
work for #5094 Create a theme model that inherits from a base class w…
Apr 12, 2024
6b0c81a
work for #5094 Create a theme model that inherits from a base class w…
Apr 15, 2024
ff0cd90
work for #5094 Create a theme model that inherits from a base class w…
Apr 18, 2024
f0a2df8
work for #5094 Create a theme model that inherits from a base class w…
Apr 18, 2024
0e3279d
work for #5094 Create a theme model that inherits from a base class w…
Apr 19, 2024
527e886
work for #5094 Create a theme model that inherits from a base class w…
Apr 22, 2024
765917a
work for #5094 Create a theme model that inherits from a base class w…
Apr 24, 2024
264b75e
work for #5094 Create a theme model that inherits from a base class w…
Apr 25, 2024
409f0b0
work for #5094 Create a theme model that inherits from a base class w…
Apr 27, 2024
d99e1dc
work for #5094 Create a theme model that inherits from a base class w…
Apr 27, 2024
1ac3f6f
Merge branch 'master' of github.com:surveyjs/survey-creator into issu…
Apr 27, 2024
034c456
work for #5094 Create a theme model that inherits from a base class w…
May 2, 2024
c2ace65
work for #5094 Create a theme model that inherits from a base class w…
May 6, 2024
17d790f
Merge branch 'master' of github.com:surveyjs/survey-creator into issu…
May 6, 2024
7bcbd33
work for #5094 Create a theme model that inherits from a base class w…
May 6, 2024
ec7b377
work for #5094 Create a theme model that inherits from a base class w…
May 7, 2024
5a2cbce
Merge branch 'master' of github.com:surveyjs/survey-creator into issu…
May 7, 2024
1d882d7
work for #5094 Create a theme model that inherits from a base class w…
May 7, 2024
a774bb2
work for #5094 Create a theme model that inherits from a base class w…
May 8, 2024
912ac95
work for #5094 Create a theme model that inherits from a base class w…
May 8, 2024
40d4631
work for #5094 Create a theme model that inherits from a base class w…
May 14, 2024
bbcd2d7
work for #5094 Fix css styles
May 14, 2024
cd1242a
work for #5094 remove comments
May 14, 2024
68bfd80
work for #5094 fix styles for dynamic panel
May 15, 2024
90fdbef
work for #5094 add custome properties
May 16, 2024
5548aa8
work for #5094 Create a theme model that inherits from a base class w…
May 16, 2024
e4ad6fc
work for #5094 Create a theme model that inherits from a base class w…
May 17, 2024
51807c6
Fix issue with onShowingProperty and visibleIf #5094
andrewtelnov May 17, 2024
c42814e
Merge branch 'issue/5094-theme-property-grid-serialization-info' of h…
andrewtelnov May 17, 2024
33a986e
Revert "Fix issue with onShowingProperty and visibleIf #5094"
May 20, 2024
e141895
work for #5094 Create a theme model that inherits from a base class w…
May 20, 2024
e59b762
Merge branch 'master' of github.com:surveyjs/survey-creator into issu…
May 21, 2024
e9e130d
work for #5094 Theme editor settings refactoring
May 21, 2024
e222198
Merge branch 'master' of github.com:surveyjs/survey-creator into issu…
May 22, 2024
f803643
work for #5094 Create a theme model that inherits from a base class w…
May 22, 2024
22bf095
work for #5094 fix visibility property grid editors
May 22, 2024
4707d8e
work for #5094 remove editor.descriptionLocation = "hidden";
May 22, 2024
42ff218
work for #5094 Create a theme model that inherits from a base class w…
May 23, 2024
5181c50
work for #5094 rename ThemeEditorModel -> ThemeTabViewModel
May 23, 2024
64456b3
work for #5094 rename ThemeEditorModel -> ThemeTabViewModel
May 24, 2024
860fdb9
work for #5094 restore checked state for advancedModeSwitcher
May 24, 2024
13d1aa0
work for #5094 renames
May 24, 2024
8ee3e65
work for #5094 renames
May 24, 2024
1a6f883
work for #5094 rename themeMode -> isPaneless
May 27, 2024
dd245e0
work for #5094 fix localization strings
May 28, 2024
cc1aa53
work for #5094 update localization strings
May 28, 2024
eea9f37
Merge branch 'master' of github.com:surveyjs/survey-creator into issu…
May 29, 2024
8004d51
work for #5094 fix russian localization
May 29, 2024
f3b954f
work for #5094 update etalon
May 29, 2024
87ba270
work for #5094 remove comments
May 29, 2024
2917fa4
work for #5094 theme plugin onPropertyGridSurveyCreated event
May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ThemeEditorModel } from "survey-creator-core";
import { ThemeTabViewModel } from "survey-creator-core";
import { Component, Input } from "@angular/core";
import { AngularComponentFactory, BaseAngular } from "survey-angular-ui";

Expand All @@ -7,9 +7,9 @@ import { AngularComponentFactory, BaseAngular } from "survey-angular-ui";
templateUrl: "./theme.component.html",
styles: [":host { display: none; }"]
})
export class ThemeTabComponent extends BaseAngular<ThemeEditorModel> {
@Input() model!: ThemeEditorModel;
protected getModel(): ThemeEditorModel {
export class ThemeTabComponent extends BaseAngular<ThemeTabViewModel> {
@Input() model!: ThemeTabViewModel;
protected getModel(): ThemeTabViewModel {
return this.model;
}
}
Expand Down
325 changes: 325 additions & 0 deletions packages/survey-creator-core/src/components/tabs/header-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
import { Base, IHeader, IJsonPropertyInfo, ILoadFromJSONOptions, ISaveToJSONOptions, ISurvey, ITheme, Serializer, HorizontalAlignment, VerticalAlignment } from "survey-core";
import { settings } from "../../creator-settings";
import { fontsettingsFromCssVariable, fontsettingsToCssVariable } from "./theme-custom-questions/font-settings";
import { assign } from "../../utils/utils";

export class HeaderModel extends Base implements IHeader {
height: number;
inheritWidthFrom: "survey" | "container";
textAreaWidth: number;
overlapEnabled: boolean;
backgroundImage: string;
backgroundImageOpacity: number;
backgroundImageFit: "contain" | "cover" | "fill" | "tile";
logoPositionX: HorizontalAlignment;
logoPositionY: VerticalAlignment;
titlePositionX: HorizontalAlignment;
titlePositionY: VerticalAlignment;
descriptionPositionX: HorizontalAlignment;
descriptionPositionY: VerticalAlignment;
public owner: ITheme;

public getSurvey(live: boolean = false): ISurvey {
return this.owner as any;
}

fromJSON(json: any, options?: ILoadFromJSONOptions): void {
super.fromJSON(json, options);
if (!!json["backgroundImageOpacity"]) this.backgroundImageOpacity = json["backgroundImageOpacity"] * 100;
}

public setCssVariables(cssVariables?: { [index: string]: string }) {
if (cssVariables) {
this["surveyTitle"] = fontsettingsFromCssVariable(this.getPropertyByName("surveyTitle"), cssVariables);
this["surveyDescription"] = fontsettingsFromCssVariable(this.getPropertyByName("surveyDescription"), cssVariables);
this["headerTitle"] = fontsettingsFromCssVariable(this.getPropertyByName("headerTitle"), cssVariables);
this["headerDescription"] = fontsettingsFromCssVariable(this.getPropertyByName("headerDescription"), cssVariables);
}

const backgroundColorValue = cssVariables["--sjs-header-backcolor"];
if (!!backgroundColorValue) {
this["backgroundColorSwitch"] = this.getBackgroundColorSwitchByValue(backgroundColorValue);
this["backgroundColor"] = this["backgroundColorSwitch"] === "custom" ? backgroundColorValue : undefined;
}
}

toJSON(options?: ISaveToJSONOptions) {
const result = super.toJSON(options);
delete result.type;
delete result.logoPosition;
delete result.headerView;

if (this.backgroundImageOpacity !== 100) {
result.backgroundImageOpacity = this.backgroundImageOpacity / 100;
}

const cssVariables = {};
Object.keys(result).forEach(key => {
if (typeof result[key] === "object") {
const property = this.getPropertyByName(key);
if (property.type === "font") {
fontsettingsToCssVariable(result[key], property, cssVariables);
delete result[key];
}

}
});
this.setHeaderBackgroundColorCssVariable(cssVariables);
result.cssVariables = cssVariables;

delete result.backgroundColorSwitch;
delete result.backgroundColor;
return result;
}

public saveToThemeJSON(json: ITheme, options?: ISaveToJSONOptions) {
const result = this.toJSON(options);
assign(json.cssVariables, result.cssVariables);
delete result.cssVariables;
if (Object.keys(result).length > 0) {
json.header = result;
}
json.headerView = this["headerView"];
}

private setHeaderBackgroundColorCssVariable(cssVariables: any) {
if (this["backgroundColorSwitch"] === "none") {
cssVariables["--sjs-header-backcolor"] = "transparent";
} else if (this["backgroundColorSwitch"] === "custom") {
cssVariables["--sjs-header-backcolor"] = this["backgroundColor"] ?? "transparent";
}
}

private getBackgroundColorSwitchByValue(backgroundColor: string) {
if (!backgroundColor) return "accentColor";
if (backgroundColor === "transparent") return "none";
return "custom";
}

public getType(): string {
return "header";
}
}

function getDefaultTitleSetting() {
const result = { family: settings.themeEditor.defaultFontFamily, weight: "700", size: 32 };
return result;
}

function getDefaultDescriptionSetting(isAdvanced?: boolean) {
const result = { family: settings.themeEditor.defaultFontFamily, weight: "400", size: 16 };
if (isAdvanced) {
result["weight"] = "600";
}
return result;
}

function getHorizontalAlignment(questionName: string, defaultValue: string): IJsonPropertyInfo {
return <IJsonPropertyInfo>{
type: "buttongroup",
name: questionName,
visibleIf: (obj) => obj.headerView === "advanced",
choices: [
{ value: "left" },
{ value: "center" },
{ value: "right", },
],
default: defaultValue,
};
}
function getVerticalAlignment(questionName: string, defaultValue: string): IJsonPropertyInfo {
return <IJsonPropertyInfo>{
type: "buttongroup",
name: questionName,
displayName: "",
visibleIf: (obj) => obj.headerView === "advanced",
choices: [
{ value: "top" },
{ value: "middle" },
{ value: "bottom" },
],
default: defaultValue,
};
}

Serializer.addClass(
"header",
[
{
type: "buttongroup",
name: "headerView",
default: "basic",
choices: [
{ value: "basic" },
{ value: "advanced" }
]
},
{
type: "buttongroup",
name: "logoPosition",
visibleIf: (obj) => obj.headerView === "basic",
default: "left",
choices: [
{ value: "left" },
{ value: "right" }
],
},
{
type: "spinedit",
name: "height",
visibleIf: (obj) => obj.headerView === "advanced",
default: 256,
onPropertyEditorUpdate: function (obj: any, editor: any) {
if (!!editor) {
editor.unit = "px";
editor.min = 0;
}
}
},
{
type: "buttongroup",
name: "inheritWidthFrom",
visibleIf: (obj) => obj.headerView === "advanced",
default: "container",
choices: [
{ value: "survey" },
{ value: "container" }
],
},
{
type: "spinedit",
name: "textAreaWidth",
visibleIf: (obj) => obj.headerView === "advanced",
default: 512,
onPropertyEditorUpdate: function (obj: any, editor: any) {
if (!!editor) {
editor.unit = "px";
editor.min = 0;
}
}
},
{
type: "buttongroup",
name: "backgroundColorSwitch",
OlgaLarina marked this conversation as resolved.
Show resolved Hide resolved
visibleIf: (obj) => obj.headerView === "advanced",
isSerializable: false,
default: "accentColor",
choices: [
{ value: "none" },
{ value: "accentColor" },
{ value: "custom" },
],
},
{
type: "color",
name: "backgroundColor",
displayName: "",
visibleIf: (obj) => obj.headerView === "advanced",
isSerializable: false,
onPropertyEditorUpdate: function (obj: any, editor: any) {
if (!!editor) {
editor.allowEmptyValue = true;
editor.enableIf = "{composite.backgroundColorSwitch} = 'custom'";
}
}
},
{
name: "backgroundImage:file",
visibleIf: (obj) => obj.headerView === "advanced",
onPropertyEditorUpdate: function (obj: any, editor: any) {
if (!!editor) {
editor.storeDataAsText = false;
editor.acceptedTypes = "image/*";
}
}
},
{
type: "buttongroup",
name: "backgroundImageFit",
displayName: "",
choices: [
{ value: "cover" },
{ value: "fill" },
{ value: "contain" },
{ value: "tile" },
],
default: "cover",
visibleIf: (obj) => obj.headerView === "advanced",
onPropertyEditorUpdate: function (obj: any, editor: any) {
if (!!editor) {
editor.enableIf = "{composite.backgroundImage} notempty";
}
}
},
{
type: "spinedit",
name: "backgroundImageOpacity",
visibleIf: (obj) => obj.headerView === "advanced",
default: 100,
onPropertyEditorUpdate: function (obj: any, editor: any) {
if (!!editor) {
editor.unit = "%";
editor.min = 0;
editor.max = 100;
editor.step = 5;
editor.titleLocation = "left";
editor.enableIf = "{composite.backgroundImage} notempty";
}
}
},
{
type: "boolean",
name: "overlapEnabled",
displayName: "",
visibleIf: (obj) => obj.headerView === "advanced",
onPropertyEditorUpdate: function (obj: any, editor: any) {
if (!!editor) {
editor.renderAs = "checkbox";
}
}
},

getHorizontalAlignment("logoPositionX", "right"),
getVerticalAlignment("logoPositionY", "top"),
getHorizontalAlignment("titlePositionX", "left"),
getVerticalAlignment("titlePositionY", "bottom"),
getHorizontalAlignment("descriptionPositionX", "left"),
getVerticalAlignment("descriptionPositionY", "bottom"),
]);

Serializer.addProperties("header", [
{
type: "font",
name: "surveyTitle",
OlgaLarina marked this conversation as resolved.
Show resolved Hide resolved
visibleIf: (obj) => obj.headerView === "basic",
default: getDefaultTitleSetting(),
},
{
type: "font",
name: "surveyDescription",
visibleIf: (obj) => obj.headerView === "basic",
default: getDefaultDescriptionSetting(),
},
{
type: "font",
name: "headerTitle",
default: getDefaultTitleSetting(),
visibleIf: (obj) => obj.headerView === "advanced",
onPropertyEditorUpdate: function (obj: any, editor: any) {
if (!!editor) {
editor.allowEmptyColorValue = true;
}
},
},
{
type: "font",
name: "headerDescription",
default: getDefaultDescriptionSetting(true),
visibleIf: (obj) => obj.headerView === "advanced",
onPropertyEditorUpdate: function (obj: any, editor: any) {
if (!!editor) {
editor.allowEmptyColorValue = true;
}
},
},
]);
Loading
Loading