AdminCustomizeContainer.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import { Container } from 'unstated';
  2. /**
  3. * Service container for admin customize setting page (Customize.jsx)
  4. * @extends {Container} unstated Container
  5. */
  6. export default class AdminCustomizeContainer extends Container {
  7. constructor(appContainer) {
  8. super();
  9. this.appContainer = appContainer;
  10. this.state = {
  11. currentTheme: appContainer.config.themeType,
  12. currentLayout: appContainer.config.layoutType,
  13. currentBehavior: appContainer.config.behaviorType,
  14. isEnabledTimeline: appContainer.config.isEnabledTimeline,
  15. isSavedStatesOfTabChanges: appContainer.config.isSavedStatesOfTabChanges,
  16. isEnabledAttachTitleHeader: appContainer.config.isEnabledAttachTitleHeader,
  17. currentRecentCreatedLimit: appContainer.config.recentCreatedLimit,
  18. currentHighlightJsStyle: appContainer.config.highlightJsStyle,
  19. isHighlightJsStyleBorderEnabled: appContainer.config.highlightJsStyleBorder,
  20. currentCustomizeHeader: appContainer.config.customizeHeader,
  21. currentCustomizeCss: appContainer.config.customizeCss,
  22. currentCustomizeScript: appContainer.config.customizeScript,
  23. };
  24. }
  25. /**
  26. * Workaround for the mangling in production build to break constructor.name
  27. */
  28. static getClassName() {
  29. return 'AdminCustomizeContainer';
  30. }
  31. /**
  32. * Switch layoutType
  33. */
  34. switchLayoutType(lauoutName) {
  35. this.setState({ currentLayout: lauoutName });
  36. }
  37. /**
  38. * Switch themeType
  39. */
  40. switchThemeType(themeName) {
  41. // can't choose theme when kibela
  42. if (this.state.currentLayout === 'kibela') {
  43. return;
  44. }
  45. this.setState({ currentTheme: themeName });
  46. }
  47. /**
  48. * Switch behaviorType
  49. */
  50. switchBehaviorType(behaviorName) {
  51. this.setState({ currentBehavior: behaviorName });
  52. }
  53. /**
  54. * Switch enabledTimeLine
  55. */
  56. switchEnableTimeline() {
  57. this.setState({ isEnabledTimeline: !this.state.isEnabledTimeline });
  58. }
  59. /**
  60. * Switch savedStatesOfTabChanges
  61. */
  62. switchSavedStatesOfTabChanges() {
  63. this.setState({ isSavedStatesOfTabChanges: !this.state.isSavedStatesOfTabChanges });
  64. }
  65. /**
  66. * Switch enabledAttachTitleHeader
  67. */
  68. switchEnabledAttachTitleHeader() {
  69. this.setState({ isEnabledAttachTitleHeader: !this.state.isEnabledAttachTitleHeader });
  70. }
  71. /**
  72. * Switch recentCreatedLimit
  73. */
  74. switchRecentCreatedLimit(value) {
  75. this.setState({ currentRecentCreatedLimit: value });
  76. }
  77. /**
  78. * Switch highlightJsStyle
  79. */
  80. switchHighlightJsStyle(value) {
  81. this.setState({ currentHighlightJsStyle: value });
  82. }
  83. /**
  84. * Switch highlightJsStyleBorder
  85. */
  86. switchHighlightJsStyleBorder() {
  87. this.setState({ isHighlightJsStyleBorderEnabled: !this.state.isHighlightJsStyleBorderEnabled });
  88. }
  89. /**
  90. * Change customize Html header
  91. */
  92. changeCustomizeHeader(inputValue) {
  93. this.setState({ currentCustomizeHeader: inputValue });
  94. }
  95. /**
  96. * Change customize css
  97. */
  98. changeCustomizeCss(inputValue) {
  99. this.setState({ currentCustomizeCss: inputValue });
  100. }
  101. /**
  102. * Change customize script
  103. */
  104. changeCustomizeScript(inpuValue) {
  105. this.setState({ currentCustomizeScript: inpuValue });
  106. }
  107. /**
  108. * Update layout
  109. * @memberOf AdminCustomizeContainer
  110. * @return {Array} Appearance
  111. */
  112. async updateCustomizeLayoutAndTheme() {
  113. const response = await this.appContainer.apiv3.put('/customize-setting/layoutTheme', {
  114. layoutType: this.state.currentLayout,
  115. themeType: this.state.currentTheme,
  116. });
  117. const { customizedParams } = response.data;
  118. return customizedParams;
  119. }
  120. /**
  121. * Update behavior
  122. * @memberOf AdminCustomizeContainer
  123. * @return {string} Behavior
  124. */
  125. async updateCustomizeBehavior() {
  126. const response = await this.appContainer.apiv3.put('/customize-setting/behavior', {
  127. behaviorType: this.state.currentBehavior,
  128. });
  129. const { customizedParams } = response.data;
  130. return customizedParams;
  131. }
  132. /**
  133. * Update function
  134. * @memberOf AdminCustomizeContainer
  135. * @return {string} Functions
  136. */
  137. async updateCustomizeFunction() {
  138. const response = await this.appContainer.apiv3.put('/customize-setting/function', {
  139. isEnabledTimeline: this.state.isEnabledTimeline,
  140. isSavedStatesOfTabChanges: this.state.isSavedStatesOfTabChanges,
  141. isEnabledAttachTitleHeader: this.state.isEnabledAttachTitleHeader,
  142. recentCreatedLimit: this.state.currentRecentCreatedLimit,
  143. });
  144. const { customizedParams } = response.data;
  145. return customizedParams;
  146. }
  147. /**
  148. * Update code highlight
  149. * @memberOf AdminCustomizeContainer
  150. * @return {Array} Code highlight
  151. */
  152. async updateHighlightJsStyle() {
  153. // TODO GW-515 create apiV3
  154. }
  155. /**
  156. * Update customHeader
  157. * @memberOf AdminCustomizeContainer
  158. * @return {string} Customize html header
  159. */
  160. async updateCustomizeHeader() {
  161. // TODO GW-601 create apiV3
  162. }
  163. /**
  164. * Update customCss
  165. * @memberOf AdminCustomizeContainer
  166. * @return {string} Customize css
  167. */
  168. async updateCustomizeCss() {
  169. const response = await this.appContainer.apiv3.put('/customize-setting/customizeCss', {
  170. customizeCss: this.state.currentCustomizeCss,
  171. });
  172. const { customizedParams } = response.data;
  173. return customizedParams;
  174. }
  175. /**
  176. * Update customize script
  177. * @memberOf AdminCustomizeContainer
  178. * @return {string} Customize scripts
  179. */
  180. async updateCustomizeScript() {
  181. const response = await this.appContainer.apiv3.put('/customize-setting/customizeScript', {
  182. customizeScript: this.state.currentCustomizeScript,
  183. });
  184. const { customizedParams } = response.data;
  185. return customizedParams;
  186. }
  187. }