Skip to content

Commit

Permalink
Add API for application themes (appsmithorg#9449)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalaji1192 authored Dec 24, 2021
1 parent 2138229 commit 1fad719
Show file tree
Hide file tree
Showing 41 changed files with 2,615 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ public interface Url {
String NOTIFICATION_URL = BASE_URL + VERSION + "/notifications";
String INSTANCE_ADMIN_URL = BASE_URL + VERSION + "/admin";
String GIT_URL = BASE_URL + VERSION + "/git";
String THEME_URL = BASE_URL + VERSION + "/themes";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.appsmith.server.controllers.ce.ApplicationControllerCE;
import com.appsmith.server.services.ApplicationPageService;
import com.appsmith.server.services.ApplicationService;
import com.appsmith.server.services.ThemeService;
import com.appsmith.server.solutions.ApplicationFetcher;
import com.appsmith.server.solutions.ApplicationForkingService;
import com.appsmith.server.solutions.ImportExportApplicationService;
Expand All @@ -14,15 +15,15 @@
@RequestMapping(Url.APPLICATION_URL)
public class ApplicationController extends ApplicationControllerCE {


public ApplicationController(ApplicationService service,
ApplicationPageService applicationPageService,
ApplicationFetcher applicationFetcher,
ApplicationForkingService applicationForkingService,
ImportExportApplicationService importExportApplicationService) {
ImportExportApplicationService importExportApplicationService,
ThemeService themeService) {

super(service, applicationPageService, applicationFetcher, applicationForkingService,
importExportApplicationService);
importExportApplicationService, themeService);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.appsmith.server.controllers;

import com.appsmith.server.constants.Url;
import com.appsmith.server.controllers.ce.ThemeControllerCE;
import com.appsmith.server.services.ThemeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(Url.THEME_URL)
public class ThemeController extends ThemeControllerCE {

public ThemeController(ThemeService themeService) {
super(themeService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.appsmith.server.domains.Application;
import com.appsmith.server.domains.ApplicationJson;
import com.appsmith.server.domains.GitAuth;
import com.appsmith.server.domains.Theme;
import com.appsmith.server.dtos.ApplicationAccessDTO;
import com.appsmith.server.dtos.ApplicationPagesDTO;
import com.appsmith.server.dtos.ResponseDTO;
Expand All @@ -13,6 +14,7 @@
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.services.ApplicationPageService;
import com.appsmith.server.services.ApplicationService;
import com.appsmith.server.services.ThemeService;
import com.appsmith.server.solutions.ApplicationFetcher;
import com.appsmith.server.solutions.ApplicationForkingService;
import com.appsmith.server.solutions.ImportExportApplicationService;
Expand All @@ -26,6 +28,7 @@
import org.springframework.http.codec.multipart.Part;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
Expand All @@ -49,19 +52,21 @@ public class ApplicationControllerCE extends BaseController<ApplicationService,
private final ApplicationFetcher applicationFetcher;
private final ApplicationForkingService applicationForkingService;
private final ImportExportApplicationService importExportApplicationService;
private final ThemeService themeService;

@Autowired
public ApplicationControllerCE(
ApplicationService service,
ApplicationPageService applicationPageService,
ApplicationFetcher applicationFetcher,
ApplicationForkingService applicationForkingService,
ImportExportApplicationService importExportApplicationService) {
ImportExportApplicationService importExportApplicationService, ThemeService themeService) {
super(service);
this.applicationPageService = applicationPageService;
this.applicationFetcher = applicationFetcher;
this.applicationForkingService = applicationForkingService;
this.importExportApplicationService = importExportApplicationService;
this.themeService = themeService;
}

@PostMapping
Expand Down Expand Up @@ -206,4 +211,10 @@ public Mono<ResponseDTO<Application>> update(@PathVariable String defaultApplica
return service.update(defaultApplicationId, resource, branchName)
.map(updatedResource -> new ResponseDTO<>(HttpStatus.OK.value(), updatedResource, null));
}

@PatchMapping("{applicationId}/themes/{themeId}")
public Mono<ResponseDTO<Theme>> setCurrentTheme(@PathVariable String applicationId, @PathVariable String themeId) {
return themeService.changeCurrentTheme(themeId, applicationId)
.map(theme -> new ResponseDTO<>(HttpStatus.OK.value(), theme, null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.appsmith.server.controllers.ce;

import com.appsmith.server.constants.Url;
import com.appsmith.server.domains.ApplicationMode;
import com.appsmith.server.domains.Theme;
import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.services.ThemeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import reactor.core.publisher.Mono;

import javax.validation.Valid;

@Slf4j
@RequestMapping(Url.THEME_URL)
public class ThemeControllerCE extends BaseController<ThemeService, Theme, String> {
public ThemeControllerCE(ThemeService themeService) {
super(themeService);
}

@GetMapping("applications/{applicationId}")
public Mono<ResponseDTO<Theme>> getThemes(@PathVariable String applicationId, @RequestParam(required = false, defaultValue = "EDIT") ApplicationMode mode) {
return service.getApplicationTheme(applicationId, mode)
.map(theme -> new ResponseDTO<>(HttpStatus.OK.value(), theme, null));
}

@PostMapping("applications/{applicationId}")
public Mono<ResponseDTO<Theme>> updateTheme(@PathVariable String applicationId, @Valid @RequestBody Theme resource) {
return service.updateTheme(applicationId, resource)
.map(theme -> new ResponseDTO<>(HttpStatus.OK.value(), theme, null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class AbstractCommentDomain extends BaseDomain {
String orgId;

/** Edit/Published Mode */
CommentMode mode;
ApplicationMode mode;


@Transient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public String getLastDeployedAt() {

Boolean forkingEnabled;

@JsonIgnore
String publishedModeThemeId;

@JsonIgnore
String editModeThemeId;

// This constructor is used during clone application. It only deeply copies selected fields. The rest are either
// initialized newly or is left up to the calling function to set.
public Application(Application application) {
Expand Down Expand Up @@ -163,5 +169,4 @@ public enum Type {
FLUID,
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class ApplicationJson {

Map<String, DecryptedSensitiveFields> decryptedFields;

Theme editModeTheme;
Theme publishedTheme;

/**
* Mapping mongoEscapedWidgets with layoutId
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.appsmith.server.domains;

public enum CommentMode {
public enum ApplicationMode {
EDIT, PUBLISHED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.appsmith.server.domains;

import com.appsmith.external.models.BaseDomain;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

@Getter
@Setter
@Document
public class Theme extends BaseDomain {
public static final String LEGACY_THEME_NAME = "classic";
public static final String DEFAULT_THEME_NAME = "classic";

@NotNull
private String name;
private Config config;
private Properties properties;
private Map<String, WidgetStyle> stylesheet;

@JsonProperty("isSystemTheme") // manually setting property name to make sure it's compatible with Gson
private boolean isSystemTheme = false; // should be false by default

@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Properties {
private Colors colors;
private BorderRadiusProperties borderRadius;
private BoxShadowProperties boxShadow;
private FontFamilyProperties fontFamily;
}

@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Colors {
private String primaryColor;
private String backgroundColor;
}

@Data
public static class Config {
private Colors colors;
private BorderRadius borderRadius;
private BoxShadow boxShadow;
private FontFamily fontFamily;
}

@Data
public static class ResponsiveAttributes {
@JsonProperty("none")
@SerializedName("none")
private String noneValue;

@JsonProperty("DEFAULT")
@SerializedName("DEFAULT")
private String defaultValue;

@JsonProperty("md")
@SerializedName("md")
private String mdValue;

@JsonProperty("lg")
@SerializedName("lg")
private String lgValue;

@JsonProperty("xl")
@SerializedName("xl")
private String xlValue;

@JsonProperty("2xl")
@SerializedName("2xl")
private String doubleXlValue;

@JsonProperty("3xl")
@SerializedName("3xl")
private String tripleXlValue;

@JsonProperty("full")
@SerializedName("full")
private String fullValue;
}

@Data
public static class BorderRadius {
private ResponsiveAttributes appBorderRadius;
}

@Data
public static class BoxShadow {
private ResponsiveAttributes appBoxShadow;
}

@Data
public static class FontFamily {
private List<String> appFont;
}

@Data
public static class FontFamilyProperties {
private String appFont;
}

@Data
public static class WidgetStyle {
private String backgroundColor;
private String borderRadius;
private String boxShadow;
private String primaryColor;
private String menuColor;
private String buttonColor;
}

@Data
public static class BorderRadiusProperties {
private String appBorderRadius;
}

@Data
public static class BoxShadowProperties {
private String appBoxShadow;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.appsmith.server.dtos;

import com.appsmith.server.domains.CommentMode;
import com.appsmith.server.domains.ApplicationMode;
import lombok.Data;

import javax.validation.constraints.NotNull;
Expand All @@ -10,5 +10,5 @@ public class CommentThreadFilterDTO {
@NotNull
private String applicationId;
private Boolean resolved;
private CommentMode mode;
private ApplicationMode mode;
}
Loading

0 comments on commit 1fad719

Please sign in to comment.