Blame view

js/app/views/StatusGrid.js 7.14 KB
ce347c54   Erdogan Furkan   Done.
1
2
3
4
5
6

Ext.define('StatusColorEditor', {
    extend: 'Ext.grid.CellEditor',
    alias: 'widget.statuscoloreditor',

    requires: [
58780dd2   Benjamin Renard   Fix bug with Colo...
7
        'amdaUI.GridColorPicker'
ce347c54   Erdogan Furkan   Done.
8
9
10
    ],

    field: {
58780dd2   Benjamin Renard   Fix bug with Colo...
11
        xtype: 'gridcolorpicker'
ce347c54   Erdogan Furkan   Done.
12
13
14
15
    },
});


a19578d1   Erdogan Furkan   Status for parame...
16
Ext.define('amdaUI.StatusGrid', {
ce347c54   Erdogan Furkan   Done.
17
    extend: 'Ext.grid.Panel',
a19578d1   Erdogan Furkan   Status for parame...
18
    alias: 'widget.statusgrid',
a19578d1   Erdogan Furkan   Status for parame...
19
    type: '',
ce347c54   Erdogan Furkan   Done.
20

a19578d1   Erdogan Furkan   Status for parame...
21
22
    catFields:['value','label','color'],
    paramFields:['minVal','maxVal','label','color'],
a19578d1   Erdogan Furkan   Status for parame...
23
24
25
    cellEditing : null,
    isCat : null,
    statusStore: null,
ce347c54   Erdogan Furkan   Done.
26
27

    constructor: function(config) {
a19578d1   Erdogan Furkan   Status for parame...
28
29
30
        if(config.type == 'cat'){
            this.isCat = true;
            this.createStore(this.catFields);
ce347c54   Erdogan Furkan   Done.
31
        }
a19578d1   Erdogan Furkan   Status for parame...
32
33
34
35
36
37
38
        else{
            this.isCat = false;
            this.createStore(this.paramFields);
        }
        if(config.status != null )
            this.parseStatus(config.status);
        
ce347c54   Erdogan Furkan   Done.
39
40
41
		this.init(config);
		this.callParent();
	},
a19578d1   Erdogan Furkan   Status for parame...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

    createStore: function(fields){
        this.statusStore=Ext.create('Ext.data.Store', {
            fields: fields,
            data:{'items':[]},
            proxy: {
                type: 'memory',
                reader: {
                    type: 'json',
                    root: 'items'
                }
            }
        });
    },
    
ce347c54   Erdogan Furkan   Done.
57
58
    onAddClick: function(grid){
        // Create a model instance
a19578d1   Erdogan Furkan   Status for parame...
59
        if(this.isCat)
c85f1120   Erdogan Furkan   Merge amdadev + C...
60
            var rec = {'value':0, 'label':'', 'color':'#000000'};
a19578d1   Erdogan Furkan   Status for parame...
61
        else
c85f1120   Erdogan Furkan   Merge amdadev + C...
62
            var rec = {'minVal':0, 'maxVal':0, 'label':'', 'color':'#000000'};
ce347c54   Erdogan Furkan   Done.
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
        
        this.statusStore.insert(0, rec);
        this.cellEditing.startEditByPosition({
            row: 0, 
            column: 0
        });
    },
    clearStore: function(){
        this.statusStore.removeAll();
    },
    onRemoveClick: function(grid, rowIndex){
        this.statusStore.removeAt(rowIndex);
    },

    rgbToHex: function(rgbArray) {
        var hex = "";
        for (var i = 0; i < rgbArray.length; i++) {
            var hexValue = Number(rgbArray[i]).toString(16);
            if (hexValue.length < 2) {
            hexValue = "0" + hexValue;
            }
            hex += hexValue;
        }
        return hex.toUpperCase();
    },
    hexToRgb: function(hex) {
c85f1120   Erdogan Furkan   Merge amdadev + C...
89
90
91
        var r = parseInt(hex.substring(1,3), 16);
        var g = parseInt(hex.substring(3,5), 16);
        var b = parseInt(hex.substring(5,7), 16);
ce347c54   Erdogan Furkan   Done.
92
93
94
95
96
97
98
        return [r, g, b];
    },

    getStatusString: function() {
        var me = this;
        var data = this.statusStore.data.items.map(function(item) {
            var label = item.get('label');
ce347c54   Erdogan Furkan   Done.
99
            var color = item.get('color');
a19578d1   Erdogan Furkan   Status for parame...
100
101
102
103
104
            if (me.isCat)
                return item.get('value') + ' : ' + label + ' [' + me.hexToRgb(color).toString().replaceAll(",",", ") + ']';
            else
                return '['+item.get('minVal')+','+item.get('maxVal')+ '] : ' + label + ' [' + me.hexToRgb(color).toString().replaceAll(",",", ") + ']';
            
ce347c54   Erdogan Furkan   Done.
105
106
107
108
109
110
111
112
113
        });

        var outputString = data.join(' - ');
        return outputString;
    },
    
    parseStatus: function(inputStr) {
        var me = this;
        var items = inputStr.split(" - ");
ce347c54   Erdogan Furkan   Done.
114
115
116
        for (var i = 0; i < items.length; i++) {
            var parts = items[i].split(" : ");
            if(parts.length > 1){
a19578d1   Erdogan Furkan   Status for parame...
117
118
119
120
121
                var vals = {};
                if(me.isCat){
                    me.statusStore.insert(i,{
                        'value': parseInt(parts[0]),
                        'label': parts[1].split(" [")[0],
c85f1120   Erdogan Furkan   Merge amdadev + C...
122
                        'color': "#"+this.rgbToHex(parts[1].split(" [")[1].slice(0, -1).split(", "))
a19578d1   Erdogan Furkan   Status for parame...
123
124
125
126
127
128
129
130
                    });
                }
                else{
                    var minMaxVals = parts[0].split('[')[1].slice(0,-1).split(",");
                    me.statusStore.insert(i,{
                        'minVal':minMaxVals[0],
                        'maxVal':minMaxVals[1],
                        'label': parts[1].split(" [")[0],
c85f1120   Erdogan Furkan   Merge amdadev + C...
131
                        'color': "#"+this.rgbToHex(parts[1].split(" [")[1].slice(0, -1).split(", "))
a19578d1   Erdogan Furkan   Status for parame...
132
133
                    });
                }
ce347c54   Erdogan Furkan   Done.
134
135
136
            }
        } 
    },
a19578d1   Erdogan Furkan   Status for parame...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    getMinValColumn: function(){
        if (!this.isCat){
            return {text : 'Min Value', dataIndex:'minVal', width: 70, editor: {xtype:'numberfield', allowBlank:false,hideTrigger:true}, menuDisabled: true};
        }
    },
    getMaxValColumn: function(){
        if (!this.isCat) {
            return {text : 'Max Value', dataIndex:'maxVal', width: 70, editor:{xtype:'numberfield', allowBlank:false,hideTrigger:true},menuDisabled: true};
        }
    },
    getValueColumn: function(){
        if (this.isCat){
            return { text: 'Value',  dataIndex: 'value',width: 55, editor: {xtype:'numberfield',allowBlank:false, hideTrigger:true},menuDisabled: true};
        }
    },

    getLabelColumn: function(){
        return { text: 'Label', dataIndex: 'label', width: 55, editor: 'textfield',menuDisabled: true,};
    },
    getColorColumn: function(){
        return {
            text: 'Color',dataIndex: 'color', width: 40, menuDisabled: true,
            renderer: function(value) {
c85f1120   Erdogan Furkan   Merge amdadev + C...
160
                return '<div style="background-color:' + value + '; margin-left: auto; \
a19578d1   Erdogan Furkan   Status for parame...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
                        margin-right: auto;width:15px;height:15px;"></div>';
            },
            editor: { xtype: 'statuscoloreditor' }
        };
    },

    getDeleteColumn:function(){
        return {
            xtype: 'actioncolumn', width: 25, sortable: false, menuDisabled: true,
            items: [{ iconCls: 'icon-delete', scope: this, handler: this.onRemoveClick }]
        };
    },

    getColumns: function(){
        if (this.isCat)
            return [ this.getValueColumn(), this.getLabelColumn(), this.getColorColumn(), this.getDeleteColumn()]
        else
            return [this.getMinValColumn(), this.getMaxValColumn(), this.getLabelColumn(), this.getColorColumn(), this.getDeleteColumn()]
    },
ce347c54   Erdogan Furkan   Done.
180
181

    init: function(config) {
a19578d1   Erdogan Furkan   Status for parame...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
        var me = this;
        me.cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {clicksToEdit: 1,
            listeners:{
                // Backgrounds of min and max cells become red if Max < Min
                edit:function(editor, context,e){
                    if(!me.isCat){
                        var color='';
                        if (context.record.get('maxVal') - context.record.get('minVal')< 0)
                            color= 'red';
                        else 
                            color='white';
                        for ( var i = 1; i<3; i++ )
                            Ext.get(context.row).down('td:nth(' + i + ')').setStyle('background-color',color);
                    }
                }
            }
        });
ce347c54   Erdogan Furkan   Done.
199
200
201
        Ext.apply(this,  {

            store:this.statusStore,
a19578d1   Erdogan Furkan   Status for parame...
202
            columns: this.getColumns(),
ce347c54   Erdogan Furkan   Done.
203
204
            selType: 'cellmodel',
            plugins: [this.cellEditing],
a19578d1   Erdogan Furkan   Status for parame...
205
            height: (this.isCat) ? 130 : 180,
ce347c54   Erdogan Furkan   Done.
206
207
208
209
            renderTo: Ext.getBody(),
            tbar: [
            {
                xtype:'text',
a19578d1   Erdogan Furkan   Status for parame...
210
                text :(me.isCat) ? 'Status Grid' : '',
ce347c54   Erdogan Furkan   Done.
211
212
213
214
215
216
217
218
219
220
            },'->',
            {
                iconCls: 'icon-add',
                text: 'New line',
                scope: this,
                handler: this.onAddClick
            }]
        });
    }

d64f3f15   Benjamin Renard   Minor fix
221
});