2
0
mirror of https://github.com/frappe/books.git synced 2025-01-23 15:18:24 +00:00

Indicators

- Replace hardcoded color values with constants
- Add remaining color styles in Indicator component
- Show Indicator in List View
This commit is contained in:
Faris Ansari 2018-07-09 20:25:24 +05:30
parent c8422eca39
commit 5375f21d30
5 changed files with 104 additions and 36 deletions

View File

@ -1,6 +1,7 @@
const BaseDocument = require('./document'); const BaseDocument = require('./document');
const frappe = require('frappejs'); const frappe = require('frappejs');
const model = require('./index') const model = require('./index')
const indicatorColor = require('frappejs/ui/constants/indicators');
module.exports = class BaseMeta extends BaseDocument { module.exports = class BaseMeta extends BaseDocument {
constructor(data) { constructor(data) {
@ -185,8 +186,8 @@ module.exports = class BaseMeta extends BaseDocument {
this.indicators = { this.indicators = {
key: 'submitted', key: 'submitted',
colors: { colors: {
0: 'gray', 0: indicatorColor.GRAY,
1: 'blue' 1: indicatorColor.BLUE
} }
} }
} }
@ -195,17 +196,17 @@ module.exports = class BaseMeta extends BaseDocument {
getIndicatorColor(doc) { getIndicatorColor(doc) {
if (frappe.isDirty(this.name, doc.name)) { if (frappe.isDirty(this.name, doc.name)) {
return 'orange'; return indicatorColor.ORANGE;
} else { } else {
if (this.indicators) { if (this.indicators) {
let value = doc[this.indicators.key]; let value = doc[this.indicators.key];
if (value) { if (value) {
return this.indicators.colors[value] || 'gray'; return this.indicators.colors[value] || indicatorColor.GRAY;
} else { } else {
return 'gray'; return indicatorColor.GRAY;
} }
} else { } else {
return 'gray'; return indicatorColor.GRAY;
} }
} }
} }

View File

@ -1,3 +1,5 @@
const indicatorColor = require('frappejs/ui/constants/indicators');
module.exports = { module.exports = {
name: "ToDo", name: "ToDo",
label: "To Do", label: "To Do",
@ -14,8 +16,8 @@ module.exports = {
indicators: { indicators: {
key: 'status', key: 'status',
colors: { colors: {
Open: 'gray', Open: indicatorColor.BLUE,
Closed: 'green' Closed: indicatorColor.GREEN
} }
}, },
"fields": [ "fields": [

View File

@ -2,8 +2,24 @@
<span :class="['indicator', 'indicator-' + color]"></span> <span :class="['indicator', 'indicator-' + color]"></span>
</template> </template>
<script> <script>
import indicatorColor from 'frappejs/ui/constants/indicators';
export default { export default {
props: ['color'] props: {
color: {
type: String,
required: true,
default: indicatorColor.GREY,
validator(value) {
const validColors = Object.values(indicatorColor);
const valid = validColors.includes(value);
if (!valid) {
console.warn(`color must be one of `, validColors);
}
return valid;
}
}
}
} }
</script> </script>
@ -14,11 +30,31 @@ export default {
display: inline-block; display: inline-block;
width: 0.5rem; width: 0.5rem;
height: 0.5rem; height: 0.5rem;
background-color: $gray-400;
border-radius: 50%; border-radius: 50%;
} }
.indicator-grey {
background-color: $gray-300;
}
.indicator-blue { .indicator-blue {
background-color: $primary; background-color: $blue;
}
.indicator-red {
background-color: $red;
}
.indicator-green {
background-color: $green;
}
.indicator-orange {
background-color: $orange;
}
.indicator-purple {
background-color: $purple;
}
.indicator-yellow {
background-color: $yellow;
}
.indicator-black {
background-color: $gray-800;
} }
</style> </style>

View File

@ -12,8 +12,12 @@
:isActive="doc.name === $route.params.name" :isActive="doc.name === $route.params.name"
:isChecked="isChecked(doc.name)" :isChecked="isChecked(doc.name)"
@clickItem="openForm(doc.name)" @clickItem="openForm(doc.name)"
@checkItem="toggleCheck(doc.name)"> @checkItem="toggleCheck(doc.name)"
{{ doc[meta.titleField || 'name'] }} >
<indicator v-if="hasIndicator" :color="getIndicatorColor(doc)" />
<span class="d-inline-block ml-2">
{{ doc[meta.titleField || 'name'] }}
</span>
</list-item> </list-item>
</ul> </ul>
</div> </div>
@ -27,20 +31,23 @@ export default {
name: 'List', name: 'List',
props: ['doctype', 'filters'], props: ['doctype', 'filters'],
components: { components: {
ListActions, ListActions,
ListItem ListItem
}, },
data() { data() {
return { return {
data: [], data: [],
checkList: [], checkList: [],
activeItem: '' activeItem: ''
} };
}, },
computed: { computed: {
meta() { meta() {
return frappe.getMeta(this.doctype); return frappe.getMeta(this.doctype);
} },
hasIndicator() {
return Boolean(this.meta.indicators);
}
}, },
created() { created() {
frappe.db.on(`change:${this.doctype}`, () => { frappe.db.on(`change:${this.doctype}`, () => {
@ -52,21 +59,29 @@ export default {
}, },
methods: { methods: {
async newDoc() { async newDoc() {
let doc = await frappe.getNewDoc(this.doctype); let doc = await frappe.getNewDoc(this.doctype);
this.$router.push(`/edit/${this.doctype}/${doc.name}`); this.$router.push(`/edit/${this.doctype}/${doc.name}`);
}, },
async updateList() { async updateList() {
const indicatorField = this.hasIndicator ? this.meta.indicators.key : null;
const fields = [
'name',
indicatorField,
this.meta.titleField,
...this.meta.keywordFields
].filter(Boolean);
const data = await frappe.db.getAll({ const data = await frappe.db.getAll({
doctype: this.doctype, doctype: this.doctype,
fields: ['name', ...this.meta.keywordFields, this.meta.titleField], fields,
filters: this.filters || null filters: this.filters || null
}); });
this.data = data; this.data = data;
}, },
openForm(name) { openForm(name) {
this.activeItem = name; this.activeItem = name;
this.$router.push(`/edit/${this.doctype}/${name}`); this.$router.push(`/edit/${this.doctype}/${name}`);
}, },
async deleteCheckedItems() { async deleteCheckedItems() {
await frappe.db.deleteMany(this.doctype, this.checkList); await frappe.db.deleteMany(this.doctype, this.checkList);
@ -74,31 +89,34 @@ export default {
}, },
toggleCheck(name) { toggleCheck(name) {
if (this.checkList.includes(name)) { if (this.checkList.includes(name)) {
this.checkList = this.checkList.filter(docname => docname !== name); this.checkList = this.checkList.filter(docname => docname !== name);
} else { } else {
this.checkList = this.checkList.concat(name); this.checkList = this.checkList.concat(name);
} }
}, },
isChecked(name) { isChecked(name) {
return this.checkList.includes(name); return this.checkList.includes(name);
},
getIndicatorColor(doc) {
return this.meta.getIndicatorColor(doc);
} }
} }
} };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "../../styles/variables"; @import "../../styles/variables";
.list-group-item { .list-group-item {
border-left: none; border-left: none;
border-right: none; border-right: none;
border-radius: 0; border-radius: 0;
} }
.list-group-item:first-child { .list-group-item:first-child {
border-top: none; border-top: none;
} }
.list-group-item:not(.active):hover { .list-group-item:not(.active):hover {
background-color: $light; background-color: $light;
} }
</style> </style>

View File

@ -0,0 +1,11 @@
module.exports = {
GRAY: 'grey',
GREY: 'grey',
BLUE: 'blue',
RED: 'red',
GREEN: 'green',
ORANGE: 'orange',
PURPLE: 'purple',
YELLOW: 'yellow',
BLACK: 'black',
}