forked from fanruan/demo-tabledata-redis
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.4 KiB
40 lines
1.4 KiB
import { model, Model } from '../../core/core'; |
|
import { ParametersType } from './parameter.typings'; |
|
|
|
@model() |
|
export class ParameterModel extends Model { |
|
static xtype = 'plugin.model.report.json.components.parameter'; |
|
|
|
childContext = <const>['selectedId', 'parameters']; |
|
|
|
state() { |
|
return { |
|
parameters: [] as ParametersType[], |
|
selectedId: '', |
|
}; |
|
} |
|
|
|
actions = { |
|
setParameters: (parameters: ParametersType[]) => { |
|
this.model.parameters = parameters; |
|
}, |
|
removeSelectedParameter: () => { |
|
this.setParameters(this.model.parameters.filter(item => item.id !== this.model.selectedId)); |
|
}, |
|
move: (type: 'up'|'down') => { |
|
if (this.model.selectedId) { |
|
const index = this.model.parameters.findIndex(item => item.id === this.model.selectedId); |
|
if (type === 'up' && index > 0) { |
|
const oldItem = this.model.parameters.splice(index, 1)[0]; |
|
this.model.parameters.splice(index - 1, 0, oldItem); |
|
} |
|
if (type === 'down' && index < this.model.parameters.length - 1) { |
|
const oldItem = this.model.parameters.splice(index, 1)[0]; |
|
this.model.parameters.splice(index + 1, 0, oldItem); |
|
} |
|
} |
|
}, |
|
} |
|
} |
|
|
|
|
|
|