|
420 | 420 | this.job = opts.job |
421 | 421 | }, |
422 | 422 | 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 |
424 | 439 | }, |
425 | 440 | 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 |
426 | 444 | if (!id && this.first()) { |
427 | 445 | id = this.first().get("id") |
428 | 446 | } |
429 | 447 | this.each(function(m){ |
430 | 448 | m.set("active", m.get("id") == id) |
431 | 449 | }) |
| 450 | + return id |
432 | 451 | }, |
433 | 452 | }); |
434 | 453 | app.ResourceVersions = Backbone.Collection.extend({ |
|
720 | 739 | }) |
721 | 740 | app.JobBuildsView = Backbone.View.extend({ |
722 | 741 | template: _.template($('#job-builds-view').html()), |
723 | | - initialize: function() { |
| 742 | + initialize: function(opts) { |
724 | 743 | this.listenTo(this.collection, "reset", this.addBuilds) |
725 | 744 | this.listenTo(this.collection, "add", this.addBuild) |
726 | 745 |
|
| 746 | + this.job = opts.job |
| 747 | + this.pipeline = opts.pipeline |
| 748 | + |
727 | 749 | var that = this |
728 | 750 | this.collection.fetch({ |
729 | 751 | 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 | + }, |
731 | 758 | }) |
732 | 759 |
|
733 | 760 | var that = this |
|
774 | 801 | }, |
775 | 802 | clickOnTab: function(event) { |
776 | 803 | 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 }); |
778 | 809 | } |
779 | 810 | }) |
780 | 811 | app.JobBuildsTabView = Backbone.View.extend({ |
|
786 | 817 | id: "t-"+this.model.get("id"), |
787 | 818 | } |
788 | 819 | }, |
789 | | - initialize: function() { |
| 820 | + initialize: function(opts) { |
790 | 821 | this.listenTo(this.model, "change", this.render) |
791 | 822 | }, |
792 | 823 | template: _.template($('#job-builds-tab-view').html()), |
|
825 | 856 | render: function () { |
826 | 857 | var data = this.model.toJSON() |
827 | 858 | 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 | | - }) |
840 | 859 | this.$el.html(this.template(data)); |
841 | 860 | return this; // enable chained calls |
842 | 861 | }, |
843 | 862 | }) |
844 | 863 | 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()), |
850 | 865 | events: { |
851 | 866 | 'click #trigger-resource': 'clickTriggerResource', |
852 | 867 | }, |
|
902 | 917 | //-------------- |
903 | 918 | app.Router = Backbone.Router.extend({ |
904 | 919 | 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', |
910 | 925 |
|
911 | | - 'pipelines/:pn/jobs/:jn/builds': 'jobBuilds', |
| 926 | + 'pipelines/:pn/jobs/:jn/builds': 'jobBuilds', |
| 927 | + 'pipelines/:pn/jobs/:jn/builds/:bid': 'jobBuilds', |
912 | 928 |
|
913 | 929 | 'pipelines/:pn/resources/:rCan/versions': 'resourceVersions', |
914 | 930 | '*notFound': 'notFound', |
|
961 | 977 | }).render().el) |
962 | 978 | }) |
963 | 979 | }, |
964 | | - jobBuilds: function(pn, jn) { |
| 980 | + jobBuilds: function(pn, jn, bid) { |
965 | 981 | this.setup(); |
966 | 982 | var promises = [] |
967 | 983 | var pp = app.pipelines.get(pn) |
|
978 | 994 | $.when.apply($, complete).done(function() { |
979 | 995 | that.contentView = new app.JobBuildsView({ |
980 | 996 | collection: builds, |
| 997 | + currentBuildID: bid, |
| 998 | + job: jb, |
| 999 | + pipeline: pp, |
981 | 1000 | }); |
982 | 1001 | $('#main').html(that.contentView.render().el) |
983 | 1002 | $('#breadcrumb').html(new app.BreadcrumbView({ |
|
0 commit comments