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)"
>
<indicator v-if="hasIndicator" :color="getIndicatorColor(doc)" />
<span class="d-inline-block ml-2">
{{ doc[meta.titleField || 'name'] }} {{ doc[meta.titleField || 'name'] }}
</span>
</list-item> </list-item>
</ul> </ul>
</div> </div>
@ -35,11 +39,14 @@ export default {
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() {
@ -56,9 +63,17 @@ export default {
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
}); });
@ -81,9 +96,12 @@ export default {
}, },
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";

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',
}