-
-
Notifications
You must be signed in to change notification settings - Fork 893
Riverlea - add stream preview/edit to admin page #32344
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c716c7c
Riverlea - add web components for viewing/previewing/editing streams
ufundo 26e69d3
Riverlea - rename Riverlea Settings => Theme Settings, add stream list
ufundo e1ba5f9
Riverlea - stream editor - restore curated options for font size
ufundo c054668
Riverlea - restore dark mode editing
ufundo 1b6c431
Riverlea theme settings - graceful handling for non-RL selection
ufundo e559a75
Riverlea editor - fix crash if try to switch before the preview is lo…
ufundo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| +--------------------------------------------------------------------+ | ||
| | Copyright CiviCRM LLC. All rights reserved. | | ||
| | | | ||
| | This work is published under the GNU AGPLv3 license with some | | ||
| | permitted exceptions and without any warranty. For full license | | ||
| | and copyright information, see https://civicrm.org/licensing | | ||
| +--------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| namespace Civi\Api4\Action\RiverleaStream; | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| * | ||
| * NOTE: in practice it's a bit weird this is a batch action, as each doTask will | ||
| * supercede the override the previous one. | ||
| * | ||
| * But it works nicely with other API tooling and allows for | ||
| * activating where ID = 5 OR where name = my_stream OR ->first based | ||
| * on your chosen order by... | ||
| */ | ||
| class Activate extends \Civi\Api4\Generic\BasicBatchAction { | ||
|
|
||
| /** | ||
| * @var string | ||
| * | ||
| * Activate this stream as 'backend' theme, 'frontend' theme | ||
| * or 'both' | ||
| */ | ||
| protected string $backOrFront = 'backend'; | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| protected function getSelect(): array { | ||
| return [ | ||
| 'name', 'label', | ||
| 'extension', 'file_prefix', | ||
| 'css_file', 'css_file_dark', | ||
| 'vars', 'vars_dark', | ||
| 'custom_css', 'custom_css_dark', | ||
| 'dark_frontend', 'dark_backend', | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| * | ||
| * Set this stream as the theme for frontend or backend | ||
| */ | ||
| protected function doTask($stream): array { | ||
| $streamName = $stream['name']; | ||
|
|
||
| // validate the theme is available for this stream | ||
| $available = \Civi::service('themes')->getAvailable(); | ||
| if (empty($available[$streamName])) { | ||
| throw new \CRM_Core_Exception("This stream is not available to select as a Civi theme. Maybe it has been disabled?"); | ||
| } | ||
|
|
||
| $themeSettings = []; | ||
|
|
||
| switch ($this->backOrFront) { | ||
| case 'backend': | ||
| $themeSettings[] = 'theme_backend'; | ||
| break; | ||
|
|
||
| case 'frontend': | ||
| $themeSettings[] = 'theme_frontend'; | ||
| break; | ||
|
|
||
| case 'both': | ||
| $themeSettings[] = 'theme_backend'; | ||
| $themeSettings[] = 'theme_frontend'; | ||
| break; | ||
|
|
||
| default: | ||
| throw new \CRM_Core_Exception("Invalid value '{$this->backOrFront}' for back or front - should be 'backend', 'frontend', or 'both'"); | ||
| } | ||
|
|
||
| foreach ($themeSettings as $setting) { | ||
| \Civi::settings()->set($setting, $streamName); | ||
| } | ||
|
|
||
| return []; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| <?php | ||
|
|
||
| namespace Civi\Riverlea\Page; | ||
|
|
||
| use Civi\Core\SettingsMetadata; | ||
| use CRM_riverlea_ExtensionUtil as E; | ||
|
|
||
| class ThemeAdmin extends \CRM_Core_Page { | ||
|
|
||
| public function run() { | ||
| // TODO: create a bundle? OR a bundler for webcomponents? | ||
| $resources = \Civi::resources(); | ||
| $resources->addScriptFile(E::SHORT_NAME, 'js/utils.js', ['weight' => 100]); | ||
| $resources->addScriptFile(E::SHORT_NAME, 'js/editor.js', ['weight' => 200]); | ||
| $resources->addScriptFile(E::SHORT_NAME, 'js/stream-list.js', ['weight' => 200]); | ||
| $resources->addStyleFile(E::SHORT_NAME, 'css/stream-list.css'); | ||
|
|
||
| if (!\Civi::service('riverlea.style_loader')->isActive()) { | ||
| \CRM_Core_Session::setStatus(E::ts('Stream previewer will not work whilst using a legacy theme'), ts('Stream Previews'), 'warning'); | ||
| } | ||
|
|
||
| // get settings for the theme page | ||
| $allSettings = SettingsMetadata::getMetadata([], NULL, TRUE, FALSE, TRUE); | ||
| $themeSettings = array_filter($allSettings, fn ($setting) => isset($setting['settings_pages']['theme'])); | ||
| // sort by theme page weight from the meta | ||
| \usort($themeSettings, fn ($a, $b) => $a['settings_pages']['theme']['weight'] - $b['settings_pages']['theme']['weight']); | ||
|
|
||
| foreach ($themeSettings as &$setting) { | ||
| $value = \Civi::settings()->get($setting['name']); | ||
|
|
||
| // render option values if applicable | ||
| // use raw value if not a valid option | ||
| if ($setting['options']) { | ||
| $valueLabel = $setting['options'][$value] ?? E::ts("%1 [unrecognised option]", [1 => $value]); | ||
| } | ||
| else { | ||
| $valueLabel = $value; | ||
| } | ||
|
|
||
| $setting['value'] = $value; | ||
| $setting['value_label'] = $valueLabel; | ||
| } | ||
|
|
||
| $this->assign('settings', $themeSettings); | ||
| $this->assign('settingsFormUrl', \Civi::url('backend://civicrm/admin/settings/theme')); | ||
|
|
||
| // when the settings form is submitted, the only way we have to refresh the values shown is by refreshing the whole page | ||
| // TODO: create a component to show settings values (with an endpoint that can render them like the above) and then | ||
| // refresh this component on submit | ||
| \Civi::resources()->addScript(' | ||
| CRM.$(function($) { | ||
| $(document).on("crmPopupFormSuccess", () => window.location.reload()); | ||
| }); | ||
| '); | ||
|
|
||
| parent::run(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* CSS rules for Riverlea stream admin */ | ||
|
|
||
| civi-riverlea-stream-list ul { | ||
| display: grid; | ||
| grid-template-columns: repeat(auto-fit, minmax(30rem, 1fr) ); | ||
| padding-left: 0; | ||
| gap: 1rem; | ||
| margin: 0; | ||
| } | ||
|
|
||
| civi-riverlea-stream-card { | ||
| display: block; | ||
| } | ||
| civi-riverlea-stream-card.is-set-preview > .panel { | ||
| outline: 2px solid var(--crm-warning-color); | ||
| } | ||
| civi-riverlea-stream-card .panel-heading { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| } | ||
| civi-riverlea-stream-card .btn.btn-stream-selected { | ||
| background-color: var(--crm-success-color); | ||
| color: var(--crm-success-text-color); | ||
| } | ||
| civi-riverlea-stream-card .btn.btn-set-preview.btn-stream-selected { | ||
| background-color: var(--crm-warning-color); | ||
| color: var(--crm-warning-text-color); | ||
| } | ||
|
|
||
| civi-riverlea-stream-card .civi-riverlea-stream-details code { | ||
| display: inline-block; | ||
| } | ||
|
|
||
| civi-riverlea-stream-list .civi-riverlea-stream-edit-dialog { | ||
| width: 100%; | ||
| } | ||
|
|
||
| civi-riverlea-stream-editor .civi-riverlea-stream-editor-preview-pane { | ||
| padding: 1rem; | ||
| } | ||
| civi-riverlea-stream-editor iframe { | ||
| width: 100%; | ||
| height: 100%; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| border: var(--crm-border); | ||
| } | ||
| civi-riverlea-stream-editor, | ||
| civi-riverlea-stream-editor fieldset { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--crm-flex-gap); | ||
| } | ||
| civi-riverlea-stream-editor .civi-riverlea-stream-colors-header { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| } | ||
| civi-riverlea-stream-editor .civi-riverlea-stream-colors-header h3 { | ||
| padding-left: 0; | ||
| } | ||
|
|
||
| civi-riverlea-stream-variable { | ||
| display: flex; | ||
| flex-flow: row; | ||
| justify-content: space-between; | ||
| } | ||
|
|
||
| civi-riverlea-stream-variable input[type="color"] { | ||
| width: 3rem; | ||
| } | ||
| civi-riverlea-stream-variable .input-group { | ||
| display: flex; | ||
| flex-flow: row nowrap; | ||
| gap: 0.5rem; | ||
| align-items: center; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has changed to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good catch thanks @vingle