mirror of
https://github.com/aelve/guide.git
synced 2024-11-29 06:23:17 +03:00
Merge remote-tracking branch 'origin/develop' into willbasky/fix-selections
This commit is contained in:
commit
c079f59379
@ -105,7 +105,7 @@
|
|||||||
|
|
||||||
<CategorySettingsDialog
|
<CategorySettingsDialog
|
||||||
v-model="isCategorySettingsDialog"
|
v-model="isCategorySettingsDialog"
|
||||||
:categoryId="category.id"
|
:category="category"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -43,40 +43,22 @@
|
|||||||
item-text="name"
|
item-text="name"
|
||||||
item-value="value"
|
item-value="value"
|
||||||
:menu-props="{ offsetY: true, closeOnClick: true }"
|
:menu-props="{ offsetY: true, closeOnClick: true }"
|
||||||
:items="categoryStatuses"
|
:items="$options.categoryStatuses"
|
||||||
v-model="categoryStatus"
|
v-model="categoryStatus"
|
||||||
label="Status"
|
label="Status"
|
||||||
class="mb-2"
|
class="mb-2"
|
||||||
/>
|
/>
|
||||||
<v-checkbox
|
<v-checkbox
|
||||||
|
v-for="section of $options.categorySections"
|
||||||
|
:key="section.value"
|
||||||
hide-details
|
hide-details
|
||||||
color="info"
|
color="info"
|
||||||
class="category-settings-dialog__checkbox"
|
class="category-settings-dialog__checkbox"
|
||||||
data-testid="CategorySettings-ItemTraitsSectionCheckbox"
|
data-testid="CategorySettings-ItemTraitsSectionCheckbox"
|
||||||
label="Pros/cons section"
|
:label="section.name"
|
||||||
value="ItemProsConsSection"
|
:value="section.value"
|
||||||
:inputValue="sections"
|
:inputValue="sections"
|
||||||
@click.native.capture.prevent.stop="updateSectionEnabling('ItemProsConsSection', 'Pros/Cons')"
|
@click.native.capture.prevent.stop="updateSectionEnabling(section.value, section.name)"
|
||||||
/>
|
|
||||||
<v-checkbox
|
|
||||||
hide-details
|
|
||||||
color="info"
|
|
||||||
class="category-settings-dialog__checkbox"
|
|
||||||
data-testid="CategorySettings-ItemEcosystemSectionCheckbox"
|
|
||||||
label="Ecosystem section"
|
|
||||||
value="ItemEcosystemSection"
|
|
||||||
:inputValue="sections"
|
|
||||||
@click.native.capture.prevent.stop="updateSectionEnabling('ItemEcosystemSection', 'Ecosystem')"
|
|
||||||
/>
|
|
||||||
<v-checkbox
|
|
||||||
hide-details
|
|
||||||
color="info"
|
|
||||||
class="category-settings-dialog__checkbox"
|
|
||||||
data-testid="CategorySettings-ItemNotesSectionCheckbox"
|
|
||||||
label="Notes section"
|
|
||||||
value="ItemNotesSection"
|
|
||||||
:inputValue="sections"
|
|
||||||
@click.native.capture.prevent.stop="updateSectionEnabling('ItemNotesSection', 'Notes')"
|
|
||||||
/>
|
/>
|
||||||
</v-form>
|
</v-form>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
@ -110,15 +92,39 @@ import Component from 'vue-class-component'
|
|||||||
import { Prop, Watch } from 'vue-property-decorator'
|
import { Prop, Watch } from 'vue-property-decorator'
|
||||||
import _isEqual from 'lodash/isEqual'
|
import _isEqual from 'lodash/isEqual'
|
||||||
import _sortBy from 'lodash/sortBy'
|
import _sortBy from 'lodash/sortBy'
|
||||||
|
import { CategoryStatus, CategorySection, ICategoryFull } from 'client/service/Category'
|
||||||
|
|
||||||
@Component
|
const categoryStatusNames = {
|
||||||
|
[CategoryStatus.finished]: 'Complete',
|
||||||
|
[CategoryStatus.inProgress]: 'Work in progress',
|
||||||
|
[CategoryStatus.toBeWritten]: 'Stub'
|
||||||
|
}
|
||||||
|
|
||||||
|
const categorySectionNames = {
|
||||||
|
[CategorySection.prosCons]: 'Pros/cons section',
|
||||||
|
[CategorySection.ecosystem]: 'Ecosystem section',
|
||||||
|
[CategorySection.notes]: 'Notes section'
|
||||||
|
}
|
||||||
|
|
||||||
|
const categoryStatuses = Object.entries(categoryStatusNames)
|
||||||
|
.map(([value, name]) => ({ value, name }))
|
||||||
|
|
||||||
|
const categorySections = Object.entries(categorySectionNames)
|
||||||
|
.map(([value, name]) => ({ value, name }))
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
// categoryStatuses, categorySections is here to use in template but without reactivity
|
||||||
|
categoryStatuses,
|
||||||
|
categorySections
|
||||||
|
})
|
||||||
export default class CategorySettingsDialog extends Vue {
|
export default class CategorySettingsDialog extends Vue {
|
||||||
@Prop(Boolean) value!: boolean
|
@Prop(Boolean) value: boolean
|
||||||
|
@Prop(Object) category: ICategoryFull
|
||||||
|
|
||||||
title: string = ''
|
title: string = null
|
||||||
group: string = ''
|
group: string = null
|
||||||
categoryStatus: object = {}
|
categoryStatus: CategoryStatus = null
|
||||||
sections: any[] = []
|
sections: CategorySection[] = []
|
||||||
initialSettings = {
|
initialSettings = {
|
||||||
title: null,
|
title: null,
|
||||||
group: null,
|
group: null,
|
||||||
@ -126,44 +132,29 @@ export default class CategorySettingsDialog extends Vue {
|
|||||||
sections: null
|
sections: null
|
||||||
}
|
}
|
||||||
isValid: boolean = false
|
isValid: boolean = false
|
||||||
|
isSectionDisableAgreed = this.isSetSectionDisableAgreedInit()
|
||||||
// TODO replace ItemProsConsSection and other to constants
|
inputValidationRules: Array<(x: string) => boolean | string> = [
|
||||||
sectionDisableWarningAgreed = {
|
|
||||||
ItemProsConsSection: false,
|
|
||||||
ItemEcosystemSection: false,
|
|
||||||
ItemNotesSection: false
|
|
||||||
}
|
|
||||||
|
|
||||||
categoryStatuses = [
|
|
||||||
{ name: 'Complete', value: 'CategoryFinished' },
|
|
||||||
{ name: 'Work in progress', value: 'CategoryWIP' },
|
|
||||||
{ name: 'Stub', value: 'CategoryStub' }
|
|
||||||
]
|
|
||||||
|
|
||||||
inputValidationRules: Function[] = [
|
|
||||||
(x: string) => !!x || 'Input can not be empty'
|
(x: string) => !!x || 'Input can not be empty'
|
||||||
]
|
]
|
||||||
|
|
||||||
get category () {
|
|
||||||
return this.$store.state.category.category
|
|
||||||
}
|
|
||||||
|
|
||||||
get hasChanges () {
|
get hasChanges () {
|
||||||
const properties = ['title', 'group', 'sections', 'categoryStatus']
|
const properties = ['title', 'group', 'sections', 'categoryStatus']
|
||||||
|
|
||||||
return properties
|
return properties
|
||||||
.some(x => {
|
.some(x => {
|
||||||
const sortIfArray = (val) => Array.isArray(val) ? _sortBy(val) : val
|
const sortIfArray = (val) => Array.isArray(val) ? _sortBy(val) : val
|
||||||
return !_isEqual(sortIfArray(this[x]), sortIfArray(this.initialSettings[x]))
|
const current = sortIfArray(this[x])
|
||||||
|
const initial = sortIfArray(this.initialSettings[x])
|
||||||
|
return !_isEqual(current, initial)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Watch('value')
|
@Watch('value')
|
||||||
onOpen () {
|
onOpen (newVal) {
|
||||||
const { category } = this
|
if (!newVal) {
|
||||||
if (!this.category) {
|
|
||||||
this.close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const { category } = this
|
||||||
this.title = category.title
|
this.title = category.title
|
||||||
this.group = category.group
|
this.group = category.group
|
||||||
this.sections = category.sections.slice()
|
this.sections = category.sections.slice()
|
||||||
@ -176,14 +167,16 @@ export default class CategorySettingsDialog extends Vue {
|
|||||||
sections: this.sections.slice()
|
sections: this.sections.slice()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sectionDisableWarningAgreed = {
|
this.isSectionDisableAgreed = this.isSetSectionDisableAgreedInit()
|
||||||
ItemProsConsSection: false,
|
}
|
||||||
ItemEcosystemSection: false,
|
|
||||||
ItemNotesSection: false
|
isSetSectionDisableAgreedInit () {
|
||||||
}
|
return Object.values(CategorySection).reduce((acc, cur) => {
|
||||||
|
acc[cur] = false
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO refactor, rewrite simpler
|
|
||||||
async updateSectionEnabling (sectionValue, sectionName) {
|
async updateSectionEnabling (sectionValue, sectionName) {
|
||||||
const index = this.sections.indexOf(sectionValue)
|
const index = this.sections.indexOf(sectionValue)
|
||||||
const isSectionDisabled = index !== -1
|
const isSectionDisabled = index !== -1
|
||||||
@ -192,17 +185,18 @@ export default class CategorySettingsDialog extends Vue {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const isOriginallyEnabled = this.category.sections.includes(sectionValue)
|
const isOriginallyEnabled = this.initialSettings.sections.includes(sectionValue)
|
||||||
const isSectionInEdit = this.$store.state.category.itemsSectionsInEdit[sectionValue].length
|
const isSectionInEdit = this.$store.state.category.itemsSectionsInEdit[sectionValue].length
|
||||||
const wasAgreedOnce = this.sectionDisableWarningAgreed[sectionValue]
|
const wasAgreedBefore = this.isSectionDisableAgreed[sectionValue]
|
||||||
if (isOriginallyEnabled && isSectionInEdit && !wasAgreedOnce) {
|
if (isOriginallyEnabled && isSectionInEdit && !wasAgreedBefore) {
|
||||||
|
const confirmText = `You have unsaved changes in one of items ${sectionName}. If you disable this section, your changes will be lost.`
|
||||||
const isConfirmed = await this._confirm({
|
const isConfirmed = await this._confirm({
|
||||||
fullText: `You have unsaved changes in one of items’ ${sectionName} section. If you disable this section, your changes will be lost.`
|
fullText: confirmText
|
||||||
})
|
})
|
||||||
if (!isConfirmed) {
|
if (!isConfirmed) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.sectionDisableWarningAgreed[sectionValue] = true
|
this.isSectionDisableAgreed[sectionValue] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sections.splice(index, 1)
|
this.sections.splice(index, 1)
|
||||||
@ -233,7 +227,7 @@ export default class CategorySettingsDialog extends Vue {
|
|||||||
margin-right: 12px;
|
margin-right: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We using fontawesome icons which turned out to be bigger than vuetify default icons
|
/* We are using fontawesome icons which turned out to be bigger than vuetify default icons
|
||||||
and checkbox icon gets some strange offset if overflow is visible */
|
and checkbox icon gets some strange offset if overflow is visible */
|
||||||
svg {
|
svg {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -49,6 +49,12 @@ export enum CategoryStatus {
|
|||||||
toBeWritten = 'CategoryStub'
|
toBeWritten = 'CategoryStub'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum CategorySection {
|
||||||
|
prosCons = 'ItemProsConsSection',
|
||||||
|
ecosystem = 'ItemEcosystemSection',
|
||||||
|
notes = 'ItemNotesSection'
|
||||||
|
}
|
||||||
|
|
||||||
export interface ICategoryInfo {
|
export interface ICategoryInfo {
|
||||||
id: string
|
id: string
|
||||||
title: string
|
title: string
|
||||||
@ -62,7 +68,8 @@ export interface ICategoryFull {
|
|||||||
title: string
|
title: string
|
||||||
group: string
|
group: string
|
||||||
status: CategoryStatus
|
status: CategoryStatus
|
||||||
description: object
|
description: object,
|
||||||
|
sections: CategorySection[],
|
||||||
items: ICategoryItem[]
|
items: ICategoryItem[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user