Skip to content

Commit

Permalink
Add Assignment feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Mar 21, 2024
1 parent 8ccc2b2 commit c769ff8
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 26 deletions.
2 changes: 1 addition & 1 deletion assets/vendor/manager/dist/index.js

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions assets/vendor/manager/src/components/helpers/Assignment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,29 @@ import { onBeforeMount, ref, computed, watch } from 'vue';
import MenuListItem from './MenuListItem.vue';
const emit = defineEmits(['update:modelValue']);
const props = defineProps({
field: { type: Object, default: null },
modelValue: { type: String, default: '{}' }
field: { type: Object, default: null },
modelValue: { type: String, default: '{}' }
});
const list = ref({});
onBeforeMount(() => {
list.value = props.field.input.value;
try {
list.value = JSON.parse(props.modelValue);
} catch (e) {
props.field.input.menu.forEach(menu => {
setDefault(menu);
});
}
});
function setDefault(menu) {
menu.links.forEach(item => {
list.value[item.id] = true;
if (item.links.length > 0) {
setDefault(item);
}
});
}
const list_text = computed(() => {
return JSON.stringify(list.value);
})
Expand Down
3 changes: 3 additions & 0 deletions framework/elements/articles/articles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@
<option value="rounded-pill">Circle</option>
</field>
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
3 changes: 3 additions & 0 deletions framework/elements/divider/divider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<field astroidgroup="general" name="color" type="astroidcolor" label="ASTROID_WIDGET_COLOR_LABEL"/>
<field astroidgroup="general" name="margin" type="astroidspacing" label="ASTROID_WIDGET_MARGIN_LABEL" />
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
3 changes: 3 additions & 0 deletions framework/elements/grid/grid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@
<option value="rounded-pill">Circle</option>
</field>
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
3 changes: 3 additions & 0 deletions framework/elements/heading/heading.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
</field>
<field astroidgroup="widget_styles" name="font_style" label="ASTROID_WIDGET_FONT_STYLES_LABEL" type="astroidtypography" columns="1" preview="false"/>
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
3 changes: 3 additions & 0 deletions framework/elements/icons/icons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<field astroidgroup="misc_options" name="color" type="astroidcolor" label="ASTROID_WIDGET_COLOR_LABEL"/>
<field astroidgroup="misc_options" name="color_hover" type="astroidcolor" label="ASTROID_WIDGET_COLOR_HOVER_LABEL"/>
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
3 changes: 3 additions & 0 deletions framework/elements/image/image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<option value="buzz-out">ASTROID_WIDGET_TRANSITION_BUZZ_OUT</option>
</field>
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
3 changes: 3 additions & 0 deletions framework/elements/imagegroup/imagegroup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
<option value="buzz-out">ASTROID_WIDGET_TRANSITION_BUZZ_OUT</option>
</field>
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
3 changes: 3 additions & 0 deletions framework/elements/navigation/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<field astroidgroup="spacing_options" name="item_margin" type="astroidspacing" label="ASTROID_WIDGET_MARGIN_LABEL" />
<field astroidgroup="spacing_options" name="item_padding" type="astroidspacing" label="ASTROID_WIDGET_PADDING_LABEL" />
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
3 changes: 3 additions & 0 deletions framework/elements/slideshow/slideshow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<option value="rounded-pill">Circle</option>
</field>
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
3 changes: 3 additions & 0 deletions framework/elements/text/text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
<field astroidgroup="content_options" type="astroiddivider" name="content_divider" />
<field astroidgroup="content_options" ngShow="[content]!==''" name="content_font_style" label="ASTROID_WIDGET_FONT_STYLES_LABEL" type="astroidtypography" columns="1" preview="false"/>
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
3 changes: 3 additions & 0 deletions framework/elements/video_button/video_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<field astroidgroup="widget_styles" ngShow="[use_border]==1" name="border_width" type="astroidrange" min="1" max="50" step="1" postfix="px" default="1" label="ASTROID_WIDGET_BORDER_WIDTH" />
<field astroidgroup="widget_styles" ngShow="[use_border]==1" name="border_color" type="astroidcolor" label="ASTROID_WIDGET_BORDER_COLOR"/>
</fieldset>
<fieldset name="assignment-settings" label="TPL_ASTROID_ASSIGNMENT_SETTINGS_LABEL" addfieldpath="/libraries/astroid/framework/fields">
<field type="astroidassignment" label="ASTROID_ASSIGN_TO_MENU_ITEM" name="assignment"/>
</fieldset>
</fields>
</form>
</element>
19 changes: 1 addition & 18 deletions framework/fields/astroidassignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Language\Multilanguage;
use Joomla\Component\Menus\Administrator\Helper\MenusHelper;

/**
* Form Field class for the Joomla Platform.
Expand Down Expand Up @@ -36,26 +35,10 @@ class JFormFieldAstroidAssignment extends FormField {
* @since 3.7.0
*/
protected function getInput() {
$menuTypes = MenusHelper::getMenuLinks();
$menus = array();
$value = \json_decode($this->value, true);
if (!empty($menuTypes)) {
foreach ($menuTypes as $type) {
if (count($type->links)) {
foreach ($type->links as $link) {
if (isset($value[$link->value])) {
$menus[$link->value] = $value[$link->value];
} else {
$menus[$link->value] = true;
}
}
}
}
}
$json = [
'id' => $this->id,
'name' => $this->name,
'value' => $menus,
'value' => \json_decode($this->value, true),
'menu' => Astroid\Helper::getMenuLinks(),
'multilanguage' => Multilanguage::isEnabled(),
'type' => strtolower($this->type),
Expand Down
14 changes: 10 additions & 4 deletions framework/library/astroid/Element/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ protected function wrap()
if (empty($this->content) || !$this->state) {
return '';
}
$app = Factory::getApplication();
$jinput = $app->input;
$menuId = $jinput->get('Itemid', 0, 'INT');
$assignment = $this->params->get('assignment', "");
if ($assignment) {
$assignment = \json_decode($assignment, true);
if (isset($assignment[$menuId]) && !$assignment[$menuId]) {
return '';
}
}
$astroid_element_visibility = $this->params->get('astroid_element_visibility', "allPage");
if ($astroid_element_visibility == "currentPage") {
$app = Factory::getApplication();
$jinput = $app->input;
$menuId = $jinput->get('Itemid', 0, 'INT');

$menu = $app->getMenu();
$item = $menu->getItem($menuId);
if (empty($item)) {
Expand Down

0 comments on commit c769ff8

Please sign in to comment.