-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from zarathustra323/primary-section
Convert lib to use queue function; create primary section component
- Loading branch information
Showing
45 changed files
with
522 additions
and
283 deletions.
There are no files selected for viewing
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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 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,119 @@ | ||
<template> | ||
<tree-select | ||
v-model="currentSection" | ||
value-format="object" | ||
:auto-load-root-options="false" | ||
:backspace-removes="false" | ||
:clearable="clearable" | ||
:default-expand-level="defaultExpandLevel" | ||
:disabled="disabled" | ||
:flat="true" | ||
:load-options="loadChoices" | ||
:multiple="false" | ||
:options="choices" | ||
:placeholder="placeholder" | ||
:required="required" | ||
:show-count="showCount" | ||
@open="$emit('open')" | ||
@close="$emit('close')" | ||
@input="emitChange" | ||
search-nested | ||
> | ||
<div slot="value-label" slot-scope="{ node }">{{ node.raw.title }}</div> | ||
<label | ||
slot="option-label" | ||
slot-scope="{ node, shouldShowCount, count, labelClassName, countClassName }" | ||
:class="labelClassName" | ||
@click="toggleExpanded(node)" | ||
> | ||
{{ node.label }} | ||
<span v-if="shouldShowCount" :class="countClassName">({{ count }})</span> | ||
</label> | ||
</tree-select> | ||
</template> | ||
|
||
<script> | ||
import TreeSelect, { LOAD_ROOT_OPTIONS } from '@riophae/vue-treeselect'; | ||
import loadChoices from '../../../utils/website-section/load-site-choices'; | ||
import createSectionNode from '../../../utils/website-section/create-node'; | ||
export default { | ||
props: { | ||
section: { | ||
type: Object, | ||
default: null, | ||
}, | ||
placeholder: { | ||
type: String, | ||
default: 'Select section; type to filter...', | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
clearable: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
showCount: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
required: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
nodeOptions: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
}, | ||
data: () => ({ | ||
choices: null, | ||
}), | ||
components: { | ||
TreeSelect, | ||
}, | ||
computed: { | ||
currentSection: { | ||
get() { | ||
return createSectionNode(this.section, this.nodeOptions); | ||
}, | ||
set() { | ||
}, | ||
}, | ||
defaultExpandLevel() { | ||
return this.choices && this.choices.length === 1 ? 1 : 0; | ||
}, | ||
}, | ||
methods: { | ||
emitChange(choice) { | ||
const section = choice ? choice.model : null; | ||
this.$emit('change', section); | ||
}, | ||
toggleExpanded(node) { | ||
const { isSite } = (node || {}).raw; | ||
// eslint-disable-next-line no-param-reassign | ||
if (isSite) node.isExpanded = !node.isExpanded; | ||
}, | ||
async loadChoices({ action }) { | ||
if (action === LOAD_ROOT_OPTIONS) { | ||
const { section } = this; | ||
const expandedIds = []; | ||
if (section) { | ||
if (section.site) expandedIds.push(section.site.id); | ||
if (section.hierarchy) expandedIds.push(...section.hierarchy.map(s => s.id)); | ||
} | ||
this.choices = await loadChoices(this.$apollo, { ...this.nodeOptions, expandedIds }); | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> |
Oops, something went wrong.