comparison app/view/window/ImportResponse.js @ 1219:746915a63a11

Updated import response window. * Show only a summary of errors and warnings * Prepare response for html fiel download
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 26 Oct 2016 16:49:26 +0200
parents def27cdd0dfa
children 4e62bc6e7250
comparison
equal deleted inserted replaced
1217:4270da0f7d3b 1219:746915a63a11
15 * Initialize the view. 15 * Initialize the view.
16 */ 16 */
17 initComponent: function() { 17 initComponent: function() {
18 var me = this; 18 var me = this;
19 var html; 19 var html;
20 var download;
21 var i18n = Lada.getApplication().bundle;
20 if (me.data && me.message) { 22 if (me.data && me.message) {
21 html = me.parseResponse(me.message, me.data); 23 html = me.parseShortResponse(me.message, me.data);
22 } 24 }
23 this.bodyStyle = {background: '#fff'}; 25 this.bodyStyle = {background: '#fff'};
24 me.items = [{ 26 me.items = [{
25 xtype: 'panel', 27 xtype: 'panel',
26 html: html, 28 html: html,
27 margin: 10, 29 margin: 10,
28 border: false 30 border: false
29 }]; 31 }];
30 32
33 me.buttons = [{
34 text: i18n.getMsg('close'),
35 scope: this,
36 name: 'close',
37 handler: this.close
38 }, {
39 text: i18n.getMsg('download'),
40 name: 'download',
41 disabled: true,
42 handler: function() {
43 var blob = new Blob([download],{type: 'text/html'});
44 saveAs(blob, 'report.html');
45 }
46 }];
31 this.callParent(arguments); 47 this.callParent(arguments);
48 download = me.parseResponse(me.message, me.data);
49 },
50
51 /**
52 * Parse the response and create a summary of the result
53 * @param msg
54 * @param data
55 */
56 parseShortResponse: function(msg, data) {
57 data = Ext.JSON.decode(data);
58 var errors = data.data.errors;
59 var warnings = data.data.warnings;
60 var out = [];
61 // There is a entry for each imported proben in the errors dict (might be
62 // empty)
63
64 var numErrors;
65 var numWarnings;
66 if (!Ext.isObject(errors)) {
67 numErrors = 0;
68 }
69 else {
70 numErrors = Object.keys(errors).length;
71 }
72 if (!Ext.isObject(warnings)) {
73 numWarnings = 0;
74 }
75 else {
76 numWarnings = Object.keys(warnings).length;
77 }
78 if (msg !== '200') {
79 out.push('Der Import der Datei ' + this.fileName +
80 ' war nicht erfolgreich. Der Importvorgang konnte ' +
81 'aufgrund eines Fehlers im Server nicht beendet werden.');
82 }
83 else {
84 if (numErrors > 0) {
85 out.push(numErrors + ' Probe(n) konnten nicht erfolgreich ' +
86 'importiert werden.');
87 out.push('<br/>');
88 out.push('<br/>');
89 }
90 if (numWarnings > 0) {
91 out.push('Bei ' + numWarnings + ' Probe(n) traten Warnungen auf. ');
92 out.push('<br/>');
93 out.push('<br/>');
94 }
95 if (numErrors > 0 || numWarnings > 0) {
96 out.push('Der ausführliche Bericht steht als Download bereit.');
97 out.push('<br/>');
98 }
99 else {
100 out.push('Die Proben wurden importiert.');
101 out.push('<br/>');
102 }
103 }
104 return out.join('');
32 }, 105 },
33 106
34 /** 107 /**
35 * Parse the Response 108 * Parse the Response
36 * @param msg the Lada-Erro-Code 109 * @param msg the Lada-Erro-Code
45 // There is a entry for each imported proben in the errors dict (might be 118 // There is a entry for each imported proben in the errors dict (might be
46 // empty) 119 // empty)
47 120
48 var numErrors; 121 var numErrors;
49 var numWarnings; 122 var numWarnings;
50 if (Ext.isEmpty(Object.keys(errors))) { 123 if (!Ext.isObject(errors)) {
51 numErrors = 0; 124 numErrors = 0;
52 } 125 }
53 else { 126 else {
54 numErrors = Object.keys(errors).length; 127 numErrors = Object.keys(errors).length;
55 } 128 }
56 if (Ext.isEmpty(Object.keys(warnings))) { 129 if (!Ext.isObject(warnings)) {
57 numWarnings = 0; 130 numWarnings = 0;
58 } 131 }
59 else { 132 else {
60 numWarnings = Object.keys(warnings).length; 133 numWarnings = Object.keys(warnings).length;
61 } 134 }
73 var msgs; 146 var msgs;
74 for (var key in errors) { 147 for (var key in errors) {
75 out.push('<li>Probe: ' + key); 148 out.push('<li>Probe: ' + key);
76 msgs = errors[key]; 149 msgs = errors[key];
77 out.push('<ol>'); 150 out.push('<ol>');
151 validation = []
152 validation.push('Validierungsfehler: ');
78 for (var i = msgs.length - 1; i >= 0; i--) { 153 for (var i = msgs.length - 1; i >= 0; i--) {
79 if (msgs[i].key === 'validation') { 154 if (msgs[i].key === 'validation') {
80 out.push('Validierungsfehler: '); 155 validation.push('<ol>');
81 out.push('<ol>'); 156 validation.push(Lada.getApplication().bundle.getMsg(msgs[i].value) + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString()) + ')');
82 for (var vKey in msgs[i].value) { 157 validation.push('</ol>');
83 out.push(Lada.getApplication().bundle.getMsg(vKey) + ': ');
84 for (var j = 0; j < msgs[i].value[vKey].length; j++) {
85 console.log(msgs[i].value[vKey][j]);
86 out.push(Lada.getApplication().bundle.getMsg(msgs[i].value[vKey][j].toString()));
87 }
88 }
89 out.push('</ol>');
90 } 158 }
91 else { 159 else {
92 out.push(msgs[i].key + 160 out.push('<li>' + msgs[i].key + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString())+'): '+msgs[i].value+'</li>')
93 ' (' + Lada.getApplication().bundle.getMsg( 161 }
94 msgs[i].code.toString()) + 162 }
95 '): ' + msgs[i].value); 163 if (validation.length > 1) {
96 } 164 out.push('<li>')
165 out.push(validation.join(''));
166 out.push('</li>')
97 } 167 }
98 out.push('</ol>'); 168 out.push('</ol>');
99 out.push('</li>'); 169 out.push('</li>');
100 } 170 }
101 out.push('</ol>'); 171 out.push('</ol>');
108 out.push('<ol>'); 178 out.push('<ol>');
109 for (key in warnings) { 179 for (key in warnings) {
110 out.push('<li>' + key); 180 out.push('<li>' + key);
111 msgs = warnings[key]; 181 msgs = warnings[key];
112 out.push('<ol>'); 182 out.push('<ol>');
183 validation = []
184 validation.push('Validierungswarnungen: ');
113 for (var i = msgs.length - 1; i >= 0; i--) { 185 for (var i = msgs.length - 1; i >= 0; i--) {
114 if (msgs[i].key === 'validation') { 186 if (msgs[i].key === 'validation') {
115 out.push('Validierungswarnungen: '); 187 validation.push('<ol>');
116 out.push('<ol>'); 188 validation.push(Lada.getApplication().bundle.getMsg(msgs[i].value) + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString()) + ')');
117 for (var vKey in msgs[i].value) { 189 validation.push('</ol>');
118 out.push(Lada.getApplication().bundle.getMsg(vKey) + ': ');
119 for (var j = 0; j < msgs[i].value[vKey].length; j++) {
120 console.log(msgs[i].value[vKey][j]);
121 out.push(Lada.getApplication().bundle.getMsg(msgs[i].value[vKey][j].toString()));
122 }
123 }
124 out.push('</ol>');
125 } 190 }
126 else { 191 else {
127 out.push('<li>' + msgs[i].key + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString())+'): '+msgs[i].value+'</li>') 192 out.push('<li>' + msgs[i].key + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString())+'): '+msgs[i].value+'</li>')
128 } 193 }
194 }
195 if (validation.length > 1) {
196 out.push('<li>')
197 out.push(validation.join(''));
198 out.push('</li>')
129 } 199 }
130 out.push('</ol>'); 200 out.push('</ol>');
131 out.push('</li>'); 201 out.push('</li>');
132 } 202 }
133 out.push('</ol>'); 203 out.push('</ol>');
134 } 204 }
135 out.push('<br/>'); 205 out.push('<br/>');
206 if (numWarnings > 0 || numErrors > 0) {
207 this.down('button[name=download]').enable();
208 }
136 } 209 }
137 console.log(out.join('')); 210 console.log(out.join(''));
138 return out.join(''); 211 return out.join('');
139 } 212 }
140 }); 213 });

http://lada.wald.intevation.org