Skip to content

Commit 64abbcd

Browse files
committed
Improving IngestionAdminT5 model fetch.
- better and user-friendlier error handling - no-fetch before the view pops up (no errors for disabled ingestion)
1 parent e11a4e0 commit 64abbcd

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

app/scripts/controller/IngestionAdminT5Controller.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@
5050

5151
initialize: function(options) {
5252

53-
// model initialization:
54-
this.model.fetch({
55-
error:function(m,r,o){
56-
console.error("Failed to fetch the ingestion scenarios!");
57-
console.error(m);
58-
console.error(r);
59-
console.error(o);
60-
}
61-
});
62-
6353
// register events the component is listenning to:
6454
this.listenTo(Communicator.mediator, "dialog:open:ingestionAdminT5", this.onIngestionAdminOpen);
6555
this.listenTo(Communicator.mediator, "dialog:close:ingestionAdminT5", this.onIngestionAdminClose);

app/scripts/models/IngestionAdminT5Model.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
config_src.ingestionEngineT5.listScenario;
1717
var IngestionAdminT5Model = Backbone.Model.extend(
1818
{
19+
failure: false,
1920
url: url_src,
2021
ToI:{}, // Time of Interest
2122
AoI:[], // Area of Interest
22-
scenarios: [] // Defined Scenarios
23+
scenarios: null // Defined Scenarios
2324
}
2425
);
2526

app/scripts/views/IngestionAdminT5View.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@
6161
is_showing : false,
6262
change_pending : false,
6363

64+
fetch_model: function(){
65+
var that = this;
66+
this.model.fetch({
67+
suppressErrors: that.model.get('failure'),
68+
error: function() {
69+
that.model.set({
70+
'failure': true,
71+
'scenarios': null
72+
});
73+
},
74+
success: function() {
75+
that.model.set({'failure': false});
76+
}
77+
});
78+
},
79+
6480
get_scenario_st : function(that, sc_id, ncn_id) {
6581
var scenarios = that.model.get('scenarios');
6682
for (var i=0; i<scenarios.length; i++)
@@ -151,7 +167,11 @@
151167
alertMessage = "No ingestion scenario defined. Create a new one by clicking on the Create Scenario button below.";
152168
}
153169
} else {
154-
alertMessage = "Failed to fetch scenarios from the Ingestion Engine!";
170+
if ( that.model.get('failure') ) {
171+
alertMessage = "Failed to fetch scenarios from the Ingestion Engine!";
172+
} else {
173+
alertMessage = "Fetching the scenarios ...";
174+
}
155175
}
156176

157177
that.$('#ingestion-alert').html(alertMessage);
@@ -219,10 +239,9 @@
219239
console.log('IngAdmT5: '+ncn_id+' ajax ' +op+ ' ' + errorThrown);
220240
}, this));
221241

222-
var idel;
223-
idel = setInterval(_.bind(function() {
242+
var idel = setInterval(_.bind(function() {
224243
if (this.change_pending) {
225-
this.model.fetch();
244+
this.fetch_model();
226245
} else {
227246
clearInterval(idel);
228247
}
@@ -252,7 +271,7 @@
252271

253272
this.$('#ingestion-alert').html("Loading scenarios from the Ingestion Engine ...");
254273

255-
this.updater.i = setInterval(_.bind(function() { this.model.fetch(); }, this ), 2250);
274+
this.updater.i = setInterval(_.bind(function() { this.fetch_model(); }, this ), 2250);
256275

257276
this.$el.draggable(
258277
{
@@ -378,10 +397,10 @@
378397

379398
onTest: function()
380399
{
381-
this.model.fetch();
400+
this.fetch_model();
382401

383402
this.updater.i = setInterval(_.bind(function() {
384-
this.model.fetch();
403+
this.fetch_model();
385404
},
386405
this ),
387406
1250);

0 commit comments

Comments
 (0)