-
Notifications
You must be signed in to change notification settings - Fork 23
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 #338 from nextcloud/refactor-#337-refactor-oop
refactor: OO approach for better handling of columns and more
- Loading branch information
Showing
45 changed files
with
1,206 additions
and
1,330 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<template> | ||
<component :is="getFormComponent" :column="column" | ||
:value.sync="value_data" /> | ||
</template> | ||
|
||
<script> | ||
import TextLineForm from '../../../shared/components/ncTable/partials/rowTypePartials/TextLineForm.vue' | ||
import TextLongForm from '../../../shared/components/ncTable/partials/rowTypePartials/TextLongForm.vue' | ||
import TextLinkForm from '../../../shared/components/ncTable/partials/rowTypePartials/TextLinkForm.vue' | ||
import NumberForm from '../../../shared/components/ncTable/partials/rowTypePartials/NumberForm.vue' | ||
import NumberStarsForm from '../../../shared/components/ncTable/partials/rowTypePartials/NumberStarsForm.vue' | ||
import NumberProgressForm from '../../../shared/components/ncTable/partials/rowTypePartials/NumberProgressForm.vue' | ||
import SelectionCheckForm from '../../../shared/components/ncTable/partials/rowTypePartials/SelectionCheckForm.vue' | ||
import SelectionForm from '../../../shared/components/ncTable/partials/rowTypePartials/SelectionForm.vue' | ||
import SelectionMultiForm from '../../../shared/components/ncTable/partials/rowTypePartials/SelectionMultiForm.vue' | ||
import DatetimeForm from '../../../shared/components/ncTable/partials/rowTypePartials/DatetimeForm.vue' | ||
import DatetimeDateForm from '../../../shared/components/ncTable/partials/rowTypePartials/DatetimeDateForm.vue' | ||
import DatetimeTimeForm from '../../../shared/components/ncTable/partials/rowTypePartials/DatetimeTimeForm.vue' | ||
import TextRichForm from '../../../shared/components/ncTable/partials/rowTypePartials/TextRichForm.vue' | ||
import { AbstractColumn } from '../../../shared/components/ncTable/mixins/columnClass.js' | ||
export default { | ||
name: 'ColumnFormComponent', | ||
components: { | ||
SelectionCheckForm, | ||
SelectionForm, | ||
SelectionMultiForm, | ||
TextLineForm, | ||
TextLongForm, | ||
TextLinkForm, | ||
TextRichForm, | ||
NumberForm, | ||
NumberStarsForm, | ||
NumberProgressForm, | ||
DatetimeForm, | ||
DatetimeDateForm, | ||
DatetimeTimeForm, | ||
}, | ||
props: { | ||
column: { | ||
type: AbstractColumn, | ||
default: null, | ||
}, | ||
value: { | ||
type: undefined, | ||
default: null, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
value_data: this.value, | ||
} | ||
}, | ||
computed: { | ||
getFormComponent() { | ||
const form = this.snakeToCamel(this.column.type) + 'Form' | ||
if (this.$options.components && this.$options.components[form]) { | ||
return form | ||
} else { | ||
throw Error('Form ' + form + ' does no exist') | ||
} | ||
}, | ||
}, | ||
watch: { | ||
value_data(val) { | ||
this.$emit('update:value', this.value_data) | ||
}, | ||
}, | ||
methods: { | ||
snakeToCamel(str) { | ||
str = str.toLowerCase().replace(/([-_][a-z])/g, group => | ||
group | ||
.toUpperCase() | ||
.replace('_', '') | ||
.replace('-', '') | ||
) | ||
return str.charAt(0).toUpperCase() + str.slice(1) | ||
}, | ||
}, | ||
} | ||
</script> |
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,103 @@ | ||
import { Filters } from './filter.js' | ||
import { MagicFields } from './magicFields.js' | ||
|
||
export class AbstractColumn { | ||
|
||
type = null | ||
|
||
constructor(data) { | ||
this.createdAt = data.createdAt | ||
this.createdBy = data.createdBy | ||
this.id = data.id | ||
this.lastEditAt = data.lastEditAt | ||
this.lastEditBy = data.lastEditBy | ||
this.mandatory = data.mandatory | ||
this.orderWeight = data.orderWeight | ||
this.tableId = data.tableId | ||
this.title = data.title | ||
this.description = data.description | ||
} | ||
|
||
canSort() { | ||
return typeof this.sort === 'function' | ||
} | ||
|
||
getPossibleOperators() { | ||
return Object.values(Filters).filter(fil => fil.goodFor.includes(this.type)) | ||
} | ||
|
||
getPossibleMagicFields() { | ||
return Object.values(MagicFields).filter(item => item.goodFor.includes(this.type)) | ||
} | ||
|
||
isSearchStringFound(cellValue, cell, searchString) { | ||
if (cellValue != null && cellValue.toLowerCase().includes(searchString)) { | ||
cell.searchStringFound = true | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
isFilterFound(filterMethod, cell) { | ||
if (filterMethod()) { | ||
cell.filterFound = true | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
} | ||
|
||
export class AbstractNumberColumn extends AbstractColumn { | ||
|
||
constructor(data) { | ||
super(data) | ||
this.numberDefault = data.numberDefault | ||
} | ||
|
||
default() { | ||
return this.numberDefault | ||
} | ||
|
||
} | ||
|
||
export class AbstractDatetimeColumn extends AbstractColumn { | ||
|
||
constructor(data) { | ||
super(data) | ||
this.datetimeDefault = data.datetimeDefault | ||
} | ||
|
||
formatValue(value) {} | ||
|
||
default() { | ||
return this.datetimeDefault | ||
} | ||
|
||
} | ||
|
||
export class AbstractTextColumn extends AbstractColumn { | ||
|
||
constructor(data) { | ||
super(data) | ||
this.textDefault = data.textDefault | ||
} | ||
|
||
default() { | ||
return this.textDefault | ||
} | ||
|
||
} | ||
|
||
export class AbstractSelectionColumn extends AbstractColumn { | ||
|
||
constructor(data) { | ||
super(data) | ||
this.selectionDefault = data.selectionDefault | ||
} | ||
|
||
default() { | ||
return this.selectionDefault | ||
} | ||
|
||
} |
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,15 @@ | ||
export const ColumnTypes = { | ||
TextLine: 'text-line', | ||
TextLong: 'text-long', | ||
TextRich: 'text-rich', | ||
Selection: 'selection', | ||
SelectionMulti: 'selection-multi', | ||
Number: 'number', | ||
SelectionCheck: 'selection-check', | ||
TextLink: 'text-link', | ||
NumberStars: 'number-stars', | ||
NumberProgress: 'number-progress', | ||
DatetimeDate: 'datetime-date', | ||
DatetimeTime: 'datetime-time', | ||
Datetime: 'datetime', | ||
} |
Oops, something went wrong.