From c3fb5f38b9bbaca0b3b2b6182fbca3725b8dbaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=93ng=20Ph=C3=A1t?= Date: Tue, 7 Dec 2021 00:08:32 +0700 Subject: [PATCH] Issue 325 Custom foyer links and text (#694) * title and description mutation * navigation customisations * text area description * no text-transform and support html * relative customise foyer link * remove unnecessary commit and close --- config/schema.py | 65 ++++++++- config/sqlfiles/create.sql | 6 + studio/media.py | 4 - ui/dashboard/src/components/NavBar.vue | 96 +++++--------- ui/dashboard/src/router/index.js | 5 + ui/dashboard/src/services/graphql/config.js | 14 +- ui/dashboard/src/store/modules/config.js | 34 ++++- ui/dashboard/src/styles/custom.scss | 1 - ui/dashboard/src/styles/mixins.scss | 1 - ui/dashboard/src/views/Home.vue | 13 +- .../backstage/Admin/FoyerCustomisation.vue | 125 ++++++++++++++++++ .../src/views/backstage/Admin/index.vue | 18 +-- 12 files changed, 289 insertions(+), 93 deletions(-) create mode 100644 ui/dashboard/src/views/backstage/Admin/FoyerCustomisation.vue diff --git a/config/schema.py b/config/schema.py index 7802f97a..b9bfe46c 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,38 @@ 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) + + return SaveConfig(success=True) + + class Mutation(graphene.ObjectType): updateTermsOfService = UpdateTermsOfService.Field() + saveConfig = SaveConfig.Field() # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/config/sqlfiles/create.sql b/config/sqlfiles/create.sql index add9830f..962698c8 100644 --- a/config/sqlfiles/create.sql +++ b/config/sqlfiles/create.sql @@ -6,3 +6,9 @@ CREATE TABLE "public"."config" ( "created_on" timestamp DEFAULT (now() at time zone 'utc'), PRIMARY KEY ("id") ); + +-- Seed foyer config +INSERT INTO "config" ("name", "value") VALUES ('FOYER_TITLE', 'CYBERFORMANCE PLATFORM'); +INSERT INTO "config" ("name", "value") VALUES ('FOYER_DESCRIPTION', '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.'); +INSERT INTO "config" ("name", "value") VALUES ('FOYER_MENU', 'UpStage User Manual (https://docs.upstage.live/) +Customise Foyer (/backstage/admin/foyer-customisation)'); \ No newline at end of file diff --git a/studio/media.py b/studio/media.py index 09e84997..26a7c16a 100644 --- a/studio/media.py +++ b/studio/media.py @@ -208,8 +208,6 @@ def mutate(self, info): local_db_session.flush() total += media.size - local_db_session.commit() - local_db_session.close() return CalcSizes(size=total) @@ -398,8 +396,6 @@ def mutate(self, info, id, approved): else: local_db_session.delete(asset_usage) local_db_session.flush() - local_db_session.commit() - local_db_session.close() permissions = DBSession.query(AssetUsageModel).filter( AssetUsageModel.asset_id == asset_id).all() return ConfirmPermission(success=True, permissions=permissions) diff --git a/ui/dashboard/src/components/NavBar.vue b/ui/dashboard/src/components/NavBar.vue index 50671b63..ede94624 100644 --- a/ui/dashboard/src/components/NavBar.vue +++ b/ui/dashboard/src/components/NavBar.vue @@ -17,63 +17,40 @@