Class: Hatio::Generators::ViewUtil
- Inherits:
-
Object
- Object
- Hatio::Generators::ViewUtil
- Defined in:
- lib/generators/hatio/util/view_util.rb
Class Method Summary collapse
-
.generate_form(resourceName, columns, options, indent) ⇒ Object
resource의 columns로 부터 form 정보를 생성하여 리턴.
-
.generate_grid(singularName, columns, options, indent) ⇒ Object
columns 정보로 부터 그리드를 생성.
-
.generate_search_items(resourceName, columns, options, indent) ⇒ Object
columns 정보로 부터 search condition items를 생성.
-
.generateNewModel(resourceName, columns, options, indent) ⇒ Object
새로운 model 생성.
-
.generateResetFilters(resourceName, columns, options, indent) ⇒ Object
columns 정보로 부터 search filter를 리셋.
-
.generateStoreFilter(resourceName, columns, options, indent) ⇒ Object
columns 정보로 부터 store filter 코드 생성.
Class Method Details
.generate_form(resourceName, columns, options, indent) ⇒ Object
resource의 columns로 부터 form 정보를 생성하여 리턴
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/generators/hatio/util/view_util.rb', line 50 def self.generate_form(resourceName, columns, , indent) output = "" indent = "\t\t" unless indent columns.each do |col| if(col.name == 'id') output << "#{indent}{ name : 'id', fieldLabel : T('label.id'), hidden : true },\n" elsif(col.name == 'domain_id') output << "#{indent}{ name : 'domain_id', value : login.current_domain_id, hidden : true },\n" elsif(col.name == 'creator_id' || col.name == 'updater_id') # skip elsif(col.name == 'created_at' || col.name == 'updated_at') output << "#{indent}{ xtype : 'datefield', name : '#{col.name}', disabled : true, fieldLabel : T('label.#{col.name}'), format : T('format.datetime') },\n" elsif(col.name == 'image_data') output << "#{indent}{ id : '#{resourceName}-image-upload', itemId : '#{resourceName}-image-upload', xtype : 'fileuploadfield', inputType : 'file', name : 'image_upload', fieldLabel : T('label.image') }, \n" output << "#{indent}{ xtype : 'textareafield', name : '#{col.name}', fieldLabel : T('label.data'), rows : 16, readOnly : true }, \n" else if(col.type == :string) output << "#{indent}{ name : '#{col.name}', fieldLabel : T('label.#{col.name}') },\n" elsif(col.type == :text) output << "#{indent}{ xtype : 'textareafield', name : '#{col.name}', fieldLabel : T('label.#{col.name}') }, \n" elsif(col.type == :boolean) output << "#{indent}{ name : '#{col.name}', fieldLabel : T('label.#{col.name}'), xtype : 'checkboxfield', inputValue : true },\n" elsif(col.type == :date) output << "#{indent}{ xtype : 'datefield', name : '#{col.name}', disabled : true, fieldLabel : T('label.#{col.name}'), format : T('format.date') },\n" elsif(col.type == :datetime) output << "#{indent}{ xtype : 'datefield', name : '#{col.name}', disabled : true, fieldLabel : T('label.#{col.name}'), format : T('format.datetime') },\n" elsif(col.type == :integer || col.type == :float || col.type == :long || col.type == :double) output << "#{indent}{ name : '#{col.name}', fieldLabel : T('label.#{col.name}'), xtype : 'numberfield' },\n" else end end end output end |
.generate_grid(singularName, columns, options, indent) ⇒ Object
columns 정보로 부터 그리드를 생성
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/generators/hatio/util/view_util.rb', line 8 def self.generate_grid(singularName, columns, , indent) output = "columns : [\n" indent = "\t\t" unless indent output << "#{indent}{ dataIndex : '_cud_flag_', hidden : true, value : '' },\n" columns.each do |col| if(col.name == 'id') output << "#{indent}{ header : T('label.id'), dataIndex : 'id', hidden : true },\n" elsif(col.name == 'name') output << "#{indent}{ header : T('label.name'), dataIndex : 'name', editor : { xtype : 'textfield', allowBlank : false } },\n" elsif(col.name == 'description') output << "#{indent}{ header : T('label.description'), dataIndex : 'description', editor : { xtype : 'textfield', allowBlank : true } },\n" elsif(col.name == 'domain_id' || col.name == 'creator_id' || col.name == 'updater_id') output << "#{indent}{ dataIndex : '#{col.name}', hidden : true },\n" elsif(col.name == 'created_at' || col.name == 'updated_at') output << "#{indent}{ header : T('label.#{col.name}'), dataIndex : '#{col.name}', xtype : 'datecolumn', disabled : true, format : T('format.datetime') },\n" else if(col.type == :string) output << "#{indent}{ header : T('label.#{col.name}'), dataIndex : '#{col.name}', editor : { xtype : 'textfield' } },\n" elsif(col.type == :text) output << "#{indent}{ header : T('label.#{col.name}'), dataIndex : '#{col.name}', editor : { xtype : 'textareafield' } },\n" elsif(col.type == :boolean) output << "#{indent}{ header : T('label.#{col.name}'), dataIndex : '#{col.name}', xtype : 'checkcolumn' },\n" elsif(col.type == :date) output << "#{indent}{ header : T('label.#{col.name}'), dataIndex : '#{col.name}', editor : { xtype : 'datefield', format : T('format.date') } },\n" elsif(col.type == :datetime) output << "#{indent}{ header : T('label.#{col.name}'), dataIndex : '#{col.name}', editor : { xtype : 'datefield', format : T('format.datetime') } },\n" elsif(col.type == :integer || col.type == :float || col.type == :long || col.type == :double) output << "#{indent}{ header : T('label.#{col.name}'), dataIndex : '#{col.name}', editor : { xtype : 'numberfield' } },\n" else end end end output << "#{indent}],\n" output end |
.generate_search_items(resourceName, columns, options, indent) ⇒ Object
columns 정보로 부터 search condition items를 생성
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/generators/hatio/util/view_util.rb', line 91 def self.generate_search_items(resourceName, columns, , indent) output = "items : [ \n" indent = "\t\t" unless indent columns.each do |col| if(col.name == 'id' || col.name == 'domain_id' || col.name == 'creator_id' || col.name == 'updater_id') elsif(col.name == 'created_at' || col.name == 'updated_at') #output << "#{indent}{ fieldLabel : T('label.#{col.name}_from'), name : '#{col.name}-gte', xtype : 'datefield', format : T('format.date') },\n" #output << "#{indent}{ fieldLabel : T('label.#{col.name}_to'), name : '#{col.name}-lte', xtype : 'datefield', format : T('format.date') },\n" else if(col.type == :string || col.type == :text) output << "#{indent}{ fieldLabel : T('label.#{col.name}'), name : '#{col.name}-like' },\n" elsif(col.type == :boolean) output << "#{indent}{ fieldLabel : T('label.#{col.name}'), name : '#{col.name}-eq', inputValue : true, xtype : 'checkboxfield', inputValue : true },\n" elsif(col.type == :date) output << "#{indent}{ fieldLabel : T('label.#{col.name}_from'), name : '#{col.name}-gte', xtype : 'datefield', format : T('format.date') },\n" output << "#{indent}{ fieldLabel : T('label.#{col.name}_to'), name : '#{col.name}-lte', xtype : 'datefield', format : T('format.date') },\n" elsif(col.type == :datetime) output << "#{indent}{ fieldLabel : T('label.#{col.name}_from'), name : '#{col.name}-gte', xtype : 'datefield', format : T('format.datetime') },\n" output << "#{indent}{ fieldLabel : T('label.#{col.name}_to'), name : '#{col.name}-lte', xtype : 'datefield', format : T('format.datetime') },\n" elsif(col.type == :integer || col.type == :float || col.type == :long || col.type == :double) output << "#{indent}{ fieldLabel : T('label.#{col.name}'), name : '#{col.name}-eq', xtype : 'numberfield' },\n" else end end end output << "#{indent}],\n" output end |
.generateNewModel(resourceName, columns, options, indent) ⇒ Object
새로운 model 생성
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/generators/hatio/util/view_util.rb', line 195 def self.generateNewModel(resourceName, columns, , indent) indent = "\t" unless indent output = "data = data || {\n" output << "#{indent}#{indent}#{indent}domain_id : login.current_domain_id,\n" columns.each do |col| if(col.name == 'domain_id' || col.name == 'creator_id' || col.name == 'updater_id' || col.name == 'created_at' || col.name == 'updated_at') else output << "#{indent}#{indent}#{indent}#{col.name} : '',\n" end end output << "#{indent}#{indent}#{indent}_cud_flag_ : 'c'};\n" output << "#{indent}#{indent}return Ext.create('#{.bundle}.model.#{resourceName}', data);" output end |
.generateResetFilters(resourceName, columns, options, indent) ⇒ Object
columns 정보로 부터 search filter를 리셋
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/generators/hatio/util/view_util.rb', line 171 def self.generateResetFilters(resourceName, columns, , indent) indent = "\t\t" unless indent output = "" columns.each do |col| if(col.name == 'id' || col.name == 'domain_id' || col.name == 'creator_id' || col.name == 'updater_id' || col.name == 'created_at' || col.name == 'updated_at') else if(col.type == :string || col.type == :text) output << "#{indent}this.findItem(' \##{col.name}_filter').setValue('');\n"; elsif(col.type == :date || col.type == :datetime) output << "#{indent}this.findItem(' \##{col.name}_filter').setValue('');\n"; elsif(col.type == :boolean || col.type == :integer || col.type == :float || col.type == :long || col.type == :double) output << "#{indent}this.findItem(' \##{col.name}_filter').setValue(false);\n"; else end end end output end |
.generateStoreFilter(resourceName, columns, options, indent) ⇒ Object
columns 정보로 부터 store filter 코드 생성
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/generators/hatio/util/view_util.rb', line 125 def self.generateStoreFilter(resourceName, columns, , indent) indent = "\t\t" unless indent output = "store.filter([ {\n" output << "#{indent}#{indent}property : 'domain_id-eq',\n" output << "#{indent}#{indent}value : login.current_domain_id\n" output << "#{indent}}, \n" columns.each do |col| if(col.name == 'id' || col.name == 'domain_id' || col.name == 'creator_id' || col.name == 'updater_id' || col.name == 'created_at' || col.name == 'updated_at') elsif(col.name.end_with?('_id')) output << "#{indent}{ \n" output << "#{indent}#{indent}property : '#{col.name}-eq',\n" output << "#{indent}#{indent}value : this.findItem(' \##{col.name}_filter').getValue()\n" output << "#{indent}},\n" else if(col.type == :string || col.type == :text) output << "#{indent}{ \n" output << "#{indent}#{indent}property : '#{col.name}-like',\n" output << "#{indent}#{indent}value : this.findItem(' \##{col.name}_filter').getValue()\n" output << "#{indent}},\n" elsif(col.type == :date || col.type == :datetime) output << "#{indent}{ \n" output << "#{indent}#{indent}property : '#{col.name}-gte',\n" output << "#{indent}#{indent}value : this.findItem(' \##{col.name}_from_filter').getValue()\n" output << "#{indent}},\n" output << "#{indent}{ \n" output << "#{indent}#{indent}property : '#{col.name}-lte',\n" output << "#{indent}#{indent}value : this.findItem(' \##{col.name}_to_filter').getValue()\n" output << "#{indent}},\n" elsif(col.type == :boolean || col.type == :integer || col.type == :float || col.type == :long || col.type == :double) output << "#{indent}{ \n" output << "#{indent}#{indent}property : '#{col.name}-eq',\n" output << "#{indent}#{indent}value : this.findItem(' \##{col.name}_filter').getValue()\n" output << "#{indent}},\n" else end end end output << "#{indent}]);\n" output end |