import '@material/web/button/elevated-button.js'
import '@material/web/button/filled-button.js'
import '@material/web/button/text-button.js'
import '@material/web/icon/icon.js'
import '@operato/data-grist/ox-grist.js'
import deepEquals from 'lodash-es/isEqual'
import gql from 'graphql-tag'
import { LitElement, css, html } from 'lit'
import { customElement, property, state, query } from 'lit/decorators.js'
import { DataGrist } from '@operato/data-grist/ox-grist.js'
import { i18next, localize } from '@operato/i18n'
import { client } from '@operato/graphql'
import { notify } from '@operato/layout'
import { FetchOption } from '@operato/data-grist'
import { CommonHeaderStyles } from '@operato/styles'
interface KpiGrade {
name: string
minValue: number
maxValue: number
score?: number
color?: string
description?: string
}
type KpiGrades = KpiGrade[]
@customElement('kpi-grade-editor')
export class KpiGradeEditor extends localize(i18next)(LitElement) {
static styles = [
CommonHeaderStyles,
css`
:host {
display: flex;
flex-direction: column;
background-color: var(--md-sys-color-surface);
}
ox-grist {
flex: 1;
}
`
]
@property({ type: Object }) kpi: any = { grades: [] }
@state() grades: KpiGrades = this.kpi?.grades || []
@state() gristConfig: any = null
@query('ox-grist') grist!: DataGrist
async firstUpdated() {
if (this.kpi?.grades) {
this.grades = [...this.kpi.grades]
}
this.gristConfig = {
list: { fields: ['name', 'minValue', 'maxValue', 'score', 'color', 'description'] },
columns: [
{ type: 'gutter', gutterName: 'row-selector', multiple: true, fixed: true },
{ type: 'gutter', gutterName: 'sequence', fixed: true },
{ type: 'gutter', gutterName: 'button', fixed: true, icon: 'add', handlers: { click: 'record-copy' } },
{ type: 'gutter', gutterName: 'button', fixed: true, icon: 'arrow_upward', handlers: { click: 'move-up' } },
{ type: 'gutter', gutterName: 'button', fixed: true, icon: 'arrow_downward', handlers: { click: 'move-down' } },
{ type: 'string', name: 'name', header: '등급명', record: { editable: true }, width: 100 },
{ type: 'number', name: 'minValue', header: '최소값', record: { editable: true }, width: 100 },
{ type: 'number', name: 'maxValue', header: '최대값', record: { editable: true }, width: 100 },
{ type: 'number', name: 'score', header: '점수', record: { editable: true }, width: 80 },
{ type: 'color', name: 'color', header: '색상', record: { editable: true }, width: 100 },
{ type: 'string', name: 'description', header: '설명', record: { editable: true }, width: 200 }
],
rows: { selectable: { multiple: true } },
pagination: { infinite: true }
}
}
render() {
return html`