From 7f82a261bc0482afa6e0417b8240addea416d387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=93ng=20Ph=C3=A1t?= Date: Sat, 4 Dec 2021 21:55:28 +0700 Subject: [PATCH 1/6] title and description mutation --- config/schema.py | 67 +++++++++-- ui/dashboard/src/router/index.js | 5 + ui/dashboard/src/services/graphql/config.js | 14 ++- ui/dashboard/src/store/modules/config.js | 6 +- ui/dashboard/src/views/Home.vue | 13 +-- .../backstage/Admin/FoyerCustomisation.vue | 110 ++++++++++++++++++ .../src/views/backstage/Admin/index.vue | 18 +-- 7 files changed, 207 insertions(+), 26 deletions(-) create mode 100644 ui/dashboard/src/views/backstage/Admin/FoyerCustomisation.vue diff --git a/config/schema.py b/config/schema.py index 7802f97a..33365911 100644 --- a/config/schema.py +++ b/config/schema.py @@ -1,6 +1,6 @@ # -*- coding: iso8859-15 -*- from os import name -from config.project_globals import ScopedSession, app +from config.project_globals import DBSession, ScopedSession, app from flask_graphql import GraphQLView from config.settings import NGINX_CONFIG_FILE, VERSION from graphene import relay @@ -28,22 +28,40 @@ def resolve_uploadLimit(self, info): return limit +def get_config(name): + config = DBSession.query(ConfigModel).filter( + ConfigModel.name == name).first() + if config: + return config.value + + class SystemConfig(graphene.ObjectType): termsOfService = graphene.String() def resolve_termsOfService(self, info): - with ScopedSession() as local_db_session: - config = local_db_session.query(ConfigModel).filter( - ConfigModel.name == TERMS_OF_SERVICE - ).first() - if config: - return config.value + return get_config(TERMS_OF_SERVICE) + + +class FoyerConfig(graphene.ObjectType): + title = graphene.String() + description = graphene.String() + menu = graphene.String() + + def resolve_title(self, info): + return get_config('FOYER_TITLE') + + def resolve_description(self, info): + return get_config('FOYER_DESCRIPTION') + + def resolve_menu(self, info): + return get_config('FOYER_MENU') class Query(graphene.ObjectType): node = relay.Node.Field() nginx = graphene.Field(NginxConfig) system = graphene.Field(SystemConfig) + foyer = graphene.Field(FoyerConfig) def resolve_nginx(self, info): return NginxConfig() @@ -51,6 +69,9 @@ def resolve_nginx(self, info): def resolve_system(self, info): return SystemConfig() + def resolve_foyer(self, info): + return FoyerConfig() + class UpdateTermsOfService(graphene.Mutation): """Mutation to update Terms of Service's URL.""" @@ -76,8 +97,40 @@ def mutate(self, info, url): return UpdateTermsOfService(url=url) +class SaveConfig(graphene.Mutation): + """Mutation to customise foyer.""" + success = graphene.Boolean(description="True if the config was saved.") + + class Arguments: + name = graphene.String( + required=True, description="The name of the config.") + value = graphene.String( + required=True, description="The value of the config.") + + # decorate this with jwt login decorator. + def mutate(self, info, name, value): + with ScopedSession() as local_db_session: + config = local_db_session.query(ConfigModel).filter( + ConfigModel.name == name).first() + + if name == TERMS_OF_SERVICE: + # Use UpdateTermsOfService mutation instead. + return SaveConfig(success=False) + + if config: + config.value = value + else: + config = ConfigModel(name=name, value=value) + local_db_session.add(config) + + local_db_session.commit() + local_db_session.close() + return SaveConfig(success=True) + + class Mutation(graphene.ObjectType): updateTermsOfService = UpdateTermsOfService.Field() + saveConfig = SaveConfig.Field() # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/ui/dashboard/src/router/index.js b/ui/dashboard/src/router/index.js index 423248e3..7e2dd13c 100644 --- a/ui/dashboard/src/router/index.js +++ b/ui/dashboard/src/router/index.js @@ -95,6 +95,11 @@ const routes = [ name: 'System Configurations', component: () => import('../views/backstage/Admin/SystemConfigurations.vue'), }, + { + path: 'foyer-customisation', + name: 'Foyer Customisation', + component: () => import('../views/backstage/Admin/FoyerCustomisation.vue'), + } ] }, { diff --git a/ui/dashboard/src/services/graphql/config.js b/ui/dashboard/src/services/graphql/config.js index 9650a429..87130e6a 100644 --- a/ui/dashboard/src/services/graphql/config.js +++ b/ui/dashboard/src/services/graphql/config.js @@ -12,6 +12,11 @@ export default { system { termsOfService } + foyer { + title + description + menu + } } `), updateTermsOfService: (variables) => client.request(gql` @@ -20,5 +25,12 @@ export default { url } } - `, variables) + `, variables), + saveConfig: (name, value) => client.request(gql` + mutation SaveConfig($name: String!, $value: String!) { + saveConfig(name: $name, value: $value) { + success + } + } + `, { name, value }), } diff --git a/ui/dashboard/src/store/modules/config.js b/ui/dashboard/src/store/modules/config.js index e31bdee4..55145605 100644 --- a/ui/dashboard/src/store/modules/config.js +++ b/ui/dashboard/src/store/modules/config.js @@ -4,7 +4,8 @@ export default { namespaced: true, state: { nginx: {}, - system: {} + system: {}, + foyer: {} }, getters: { uploadLimit(state) { @@ -12,6 +13,9 @@ export default { }, termsOfService(state) { return state.system.termsOfService + }, + foyer(state) { + return state.foyer } }, mutations: { diff --git a/ui/dashboard/src/views/Home.vue b/ui/dashboard/src/views/Home.vue index 728b3661..2187565e 100644 --- a/ui/dashboard/src/views/Home.vue +++ b/ui/dashboard/src/views/Home.vue @@ -2,14 +2,8 @@
-

CYBERFORMANCE PLATFORM

-

- UpStage is an online venue for live performance: remote performers - collaborate in real time using digital media, and online audiences - anywhere in the world join events by going to a web page, without - having to download and install any additional software. UpStage is - available free to anyone who would like to use it. -

+

{{ foyer.title }}

+

{{ foyer.description }}