Skip to content

Commit a4ad28f

Browse files
authored
qid/view: Made the view not re-render all the view (#122)
1 parent 4e78b16 commit a4ad28f

File tree

2 files changed

+49
-30
lines changed

2 files changed

+49
-30
lines changed

qid/testdata/cron.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "cron" "my_cron" {
2-
check_interval = "@every 5s"
2+
check_interval = "@every 10s"
33
params {}
44
}
55

qid/transport/http/templates/views/layouts/index.tmpl

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,34 @@
420420
this.job = opts.job
421421
},
422422
parse: function(response) {
423-
return response.data;
423+
var builds = response.data;
424+
_.each(builds, function(data) {
425+
if (data.duration !== 0) {
426+
data.duration = durationToString(data.duration)
427+
}
428+
_.each(data.get, function(g, i) {
429+
data.get[i].duration = durationToString(g.duration)
430+
})
431+
_.each(data.task, function(t, i) {
432+
data.task[i].duration = durationToString(t.duration)
433+
})
434+
_.each(data.job, function(j, i) {
435+
data.job[i].duration = durationToString(j.duration)
436+
})
437+
})
438+
return builds
424439
},
425440
setActive: function(id) {
441+
// We make the id an int in case it comes
442+
// from the URL which it's a string
443+
id = id*1
426444
if (!id && this.first()) {
427445
id = this.first().get("id")
428446
}
429447
this.each(function(m){
430448
m.set("active", m.get("id") == id)
431449
})
450+
return id
432451
},
433452
});
434453
app.ResourceVersions = Backbone.Collection.extend({
@@ -720,14 +739,22 @@
720739
})
721740
app.JobBuildsView = Backbone.View.extend({
722741
template: _.template($('#job-builds-view').html()),
723-
initialize: function() {
742+
initialize: function(opts) {
724743
this.listenTo(this.collection, "reset", this.addBuilds)
725744
this.listenTo(this.collection, "add", this.addBuild)
726745

746+
this.job = opts.job
747+
this.pipeline = opts.pipeline
748+
727749
var that = this
728750
this.collection.fetch({
729751
reset: true,
730-
success: function(){ that.collection.setActive() },
752+
success: function(){
753+
var bid = that.collection.setActive(opts.currentBuildID)
754+
that.currentBuildID = bid
755+
var url = new URL(location.origin+"/pipelines/"+that.pipeline.get("name")+"/jobs/"+that.job.get("name")+"/builds/"+bid)
756+
app.router.navigate(url.pathname, { trigger: false });
757+
},
731758
})
732759

733760
var that = this
@@ -774,7 +801,11 @@
774801
},
775802
clickOnTab: function(event) {
776803
event.preventDefault();
777-
this.collection.setActive(event.target.id.split("-")[1])
804+
var bid = event.target.id.split("-")[1]
805+
this.collection.setActive(bid)
806+
this.currentBuildID = bid
807+
var url = new URL(location.origin+"/pipelines/"+this.pipeline.get("name")+"/jobs/"+this.job.get("name")+"/builds/"+bid)
808+
app.router.navigate(url.pathname, { trigger: false });
778809
}
779810
})
780811
app.JobBuildsTabView = Backbone.View.extend({
@@ -786,7 +817,7 @@
786817
id: "t-"+this.model.get("id"),
787818
}
788819
},
789-
initialize: function() {
820+
initialize: function(opts) {
790821
this.listenTo(this.model, "change", this.render)
791822
},
792823
template: _.template($('#job-builds-tab-view').html()),
@@ -825,28 +856,12 @@
825856
render: function () {
826857
var data = this.model.toJSON()
827858
data.active = this.model.get("active")
828-
if (data.duration !== 0) {
829-
data.duration = durationToString(data.duration)
830-
}
831-
_.each(data.get, function(g, i) {
832-
data.get[i].duration = durationToString(g.duration)
833-
})
834-
_.each(data.task, function(t, i) {
835-
data.task[i].duration = durationToString(t.duration)
836-
})
837-
_.each(data.job, function(j, i) {
838-
data.job[i].duration = durationToString(j.duration)
839-
})
840859
this.$el.html(this.template(data));
841860
return this; // enable chained calls
842861
},
843862
})
844863
app.ResourceVersionsView = Backbone.View.extend({
845-
template: _.template($('#resource-versions-view').html(),{
846-
imports: {
847-
formatDate(d, f) {},
848-
},
849-
}),
864+
template: _.template($('#resource-versions-view').html()),
850865
events: {
851866
'click #trigger-resource': 'clickTriggerResource',
852867
},
@@ -902,13 +917,14 @@
902917
//--------------
903918
app.Router = Backbone.Router.extend({
904919
routes: {
905-
'' : 'pipelinesIndex',
906-
'pipelines' : 'pipelinesIndex',
907-
'pipelines/new' : 'pipelinesNew',
908-
'pipelines/:pn': 'pipelinesShow',
909-
'pipelines/:pn/edit' : 'pipelinesEdit',
920+
'' : 'pipelinesIndex',
921+
'pipelines' : 'pipelinesIndex',
922+
'pipelines/new' : 'pipelinesNew',
923+
'pipelines/:pn': 'pipelinesShow',
924+
'pipelines/:pn/edit' : 'pipelinesEdit',
910925

911-
'pipelines/:pn/jobs/:jn/builds': 'jobBuilds',
926+
'pipelines/:pn/jobs/:jn/builds': 'jobBuilds',
927+
'pipelines/:pn/jobs/:jn/builds/:bid': 'jobBuilds',
912928

913929
'pipelines/:pn/resources/:rCan/versions': 'resourceVersions',
914930
'*notFound': 'notFound',
@@ -961,7 +977,7 @@
961977
}).render().el)
962978
})
963979
},
964-
jobBuilds: function(pn, jn) {
980+
jobBuilds: function(pn, jn, bid) {
965981
this.setup();
966982
var promises = []
967983
var pp = app.pipelines.get(pn)
@@ -978,6 +994,9 @@
978994
$.when.apply($, complete).done(function() {
979995
that.contentView = new app.JobBuildsView({
980996
collection: builds,
997+
currentBuildID: bid,
998+
job: jb,
999+
pipeline: pp,
9811000
});
9821001
$('#main').html(that.contentView.render().el)
9831002
$('#breadcrumb').html(new app.BreadcrumbView({

0 commit comments

Comments
 (0)