Skip to content

Commit

Permalink
Feature Enable/Disable widget in Article #801
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Sep 11, 2024
1 parent 1ed3138 commit 2834fe3
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 39 deletions.
2 changes: 1 addition & 1 deletion assets/vendor/manager/dist/index.css

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions assets/vendor/manager/dist/index.html

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions assets/vendor/manager/dist/index.js

Large diffs are not rendered by default.

37 changes: 33 additions & 4 deletions assets/vendor/manager/src/Article.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,52 @@ function saveElement(params) {
return true;
});
}
function elementState(widget) {
if (typeof widget.state === 'undefined') {
widget.state = 0;
} else {
widget.state = Math.abs(widget.state - 1);
}
const action_link = 'index.php?option=com_ajax&astroid=saveArticleElement&ts='+Date.now();
const formData = new FormData();
formData.append(data.constant.astroid_admin_token, 1);
formData.append('article_id', data.article_id);
formData.append('template', data.template);
formData.append('data', JSON.stringify(widget));
save_disabled.value = true;
axios.post(action_link, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
}).then((response) => {
if (response.data.status === 'success') {
save_disabled.value = false;
}
}).catch((err) => {
console.error(err);
});
}
</script>
<template>
<div class="article-layout-data row row-cols-xl-4 row-cols-lg-3 row-cols-md-2 row-cols-sm-1 row-cols-2 g-4">
<div v-for="widget in widgets">
<div class="article-widget card card-body border">
<div class="article-widget card card-body border" :class="{'element-disabled' : !widget.state}">
<div class="d-flex justify-content-between">
<div class="widget-name">
<div><i class="text-body-tertiary me-2" :class="data.constant.form_template[widget.type].info.icon"></i>{{ widget.params.find((param) => param.name === 'title').value }}</div>
<div class="text-body-tertiary form-text">{{ widget.type }}</div>
</div>
<div class="widget-toolbar">
<ul class="nav">
<ul v-if="!save_disabled" class="nav">
<li class="nav-item">
<a class="nav-link py-0 px-1" href="#" @click.prevent="editElement(widget)"><i class="fas fa-pencil-alt me-1"></i>Edit</a>
</li>
<li class="nav-item">
<a v-if="!save_disabled" class="nav-link py-0 px-1" href="#" @click.prevent="editElement(widget)"><i class="fas fa-pencil-alt"></i> Edit</a>
<i v-else class="fa-solid fa-spinner fa-spin-pulse"></i>
<a class="nav-link py-0 px-1" href="#" data-bs-toggle="tooltip" data-bs-title="Enable/Disable Element" @click.prevent="elementState(widget)"><i class="me-1" :class="{'fas fa-eye' : widget.state, 'fas fa-eye-slash' : !widget.state}"></i>{{ (widget.state ? 'Enabled' : 'Disabled') }}</a>
</li>
</ul>
<i v-else class="fa-solid fa-spinner fa-spin-pulse"></i>
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions assets/vendor/manager/src/assets/article_data.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
}
}
}
.element-disabled {
background-image: linear-gradient(45deg, rgba(100, 100, 100, 0.15) 25%, transparent 25%, transparent 50%, rgba(100, 100, 100, 0.15) 50%, rgba(100, 100, 100, 0.15) 75%, transparent 75%, transparent) !important;
background-size: 1rem 1rem !important;
}
}
.admin .as-article-widget-data {
--bs-body-bg: var(--body-bg);
Expand Down
1 change: 1 addition & 0 deletions framework/fields/astroidlayoutdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ protected function getInput() {
if (file_exists($article_data)) {
$widget_data = file_get_contents($article_data);
$widget_data = json_decode($widget_data, true);
$element['state'] = $widget_data['state'];
$element['params'] = array_merge($element['params'], $widget_data['params']);
}
$widgets[] = $element;
Expand Down
2 changes: 1 addition & 1 deletion framework/fields/astroidmedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getInput() {
'value' => $this->value,
'media' => (string) $mediaType,
'mediaPath' => Media::getPath(),
'ajax' => Uri::root().'administrator/index.php?option=com_ajax&astroid=media',
'ajax' => Uri::root('base').'/administrator/index.php?option=com_ajax&astroid=media',
'type' => strtolower($this->type),
'lang' => [
'select_media' => Text::_('TPL_ASTROID_SELECT_'.strtoupper($mediaType)),
Expand Down
1 change: 1 addition & 0 deletions framework/library/astroid/Element/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function _content()
$article_json = file_get_contents($layout_path);
$article_data = json_decode($article_json, true);
$article_params = Helper::loadParams($article_data['params']);
$this->state = $article_data['state'];
$this->params->merge($article_params);
}
}
Expand Down

0 comments on commit 2834fe3

Please sign in to comment.