~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/javascript/branchmergeproposal.updater.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2012-01-04 03:03:41 UTC
  • mfrom: (14616.1.2 longpoll-stats-903586)
  • Revision ID: launchpad@pqm.canonical.com-20120104030341-os86i70cbyvzdjc5
[r=gmb][bug=903586] Update the stats on a MP page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
        },
33
33
 
34
34
        /**
 
35
         * The summary node.
 
36
         *
 
37
         * @attribute summary_node
 
38
         */
 
39
        summary_node: {
 
40
            value: null,
 
41
            writeOnce: "initOnly"
 
42
        },
 
43
 
 
44
        /**
35
45
         * Whether or not this MP is still 'pending'.
36
46
         *
37
47
         * @attribute pending
46
56
        },
47
57
 
48
58
        /**
 
59
         * The HTML code for the stats diff.
 
60
         *
 
61
         * @attribute diff_stats
 
62
         */
 
63
        diff_stats: {
 
64
            getter: function() {
 
65
                var summary_node = this.get('summary_node');
 
66
                if (!Y.Lang.isValue(summary_node) ||
 
67
                    !Y.Lang.isValue(summary_node.one(
 
68
                         '#summary-row-b-diff'))) {
 
69
                    return null;
 
70
                }
 
71
                return summary_node.one(
 
72
                    '#summary-row-b-diff').one('td').get('innerHTML');
 
73
            },
 
74
            setter: function(value) {
 
75
               this._setup_diff_stats_container();
 
76
               var container = this.get(
 
77
                   'summary_node').one('#summary-row-b-diff').one('td');
 
78
               container.set('innerHTML', value);
 
79
            }
 
80
        },
 
81
 
 
82
        /**
49
83
         * The HTML code for the diff.
50
84
         *
51
85
         * @attribute diff
78
112
     * @method initializer
79
113
     * @protected
80
114
     */
81
 
    initializer: function(){
 
115
    initializer: function(cfg){
82
116
        // If we have not been provided with a Launchpad Client, then
83
117
        // create one now:
84
118
        if (null === this.get("lp_client")){
85
119
            // Create our own instance of the LP client.
86
120
            this.set("lp_client", new Y.lp.client.Launchpad());
87
121
        }
88
 
        var self = this;
 
122
        this.set('summary_node', cfg.summary_node);
89
123
    },
90
124
 
91
125
    /*
146
180
    },
147
181
 
148
182
    /*
 
183
     * Add a row in the page summary table to display the diff stats
 
184
     * if needed.
 
185
     *
 
186
     * @method _setup_diff_stats_container
 
187
     */
 
188
     _setup_diff_stats_container: function() {
 
189
        if (!Y.Lang.isValue(this.get('diff_stats'))) {
 
190
            var summary_node = this.get('summary_node');
 
191
            var diff_stats = Y.Node.create('<tr />')
 
192
                .set('id', 'summary-row-b-diff')
 
193
                .append(Y.Node.create('<th />')
 
194
                    .set("text", "Diff against target:"))
 
195
                .append(Y.Node.create('<td />'));
 
196
            summary_node.one(
 
197
                '#summary-row-9-target-branch').insert(diff_stats, 'after');
 
198
        }
 
199
     },
 
200
 
 
201
    /*
149
202
     * Populate the widget with the required nodes to display the diff
150
203
     * if needed.
151
204
     *
167
220
    },
168
221
 
169
222
    /*
170
 
     * Update the diff content with the last version.
 
223
     * Update the page with the last version of the diff and update the
 
224
     * stats.
171
225
     *
172
226
     * @method update
173
227
     */
174
228
    update: function() {
 
229
        this.update_stats();
 
230
        this.update_diff();
 
231
    },
 
232
 
 
233
    /*
 
234
     * Update the diff stats with the last version.
 
235
     *
 
236
     * @method update_stats
 
237
     */
 
238
    update_stats: function() {
 
239
        var self = this;
 
240
        var config = {
 
241
            on: {
 
242
                success: function(diff_stats) {
 
243
                    self.set('diff_stats', diff_stats);
 
244
                    // (re)connect the js scroller link.
 
245
                    Y.lp.code.branchmergeproposal.reviewcomment.link_scroller(
 
246
                        '#proposal-summary a.diff-link', '#review-diff');
 
247
                    var node = self.get('summary_node');
 
248
                    Y.lp.anim.green_flash({node: node}).run();
 
249
                },
 
250
                failure: function() {
 
251
                    var node = self.get('summary_node');
 
252
                    Y.lp.anim.red_flash({node: node}).run();
 
253
                }
 
254
            }
 
255
        };
 
256
        var mp_uri = LP.cache.context.web_link;
 
257
        this.get('lp_client').get(mp_uri + "/++diff-stats", config);
 
258
     },
 
259
 
 
260
 
 
261
    /*
 
262
     * Update the diff content with the last version.
 
263
     *
 
264
     * @method update_diff
 
265
     */
 
266
    update_diff: function() {
175
267
        var self = this;
176
268
        var config = {
177
269
            on: {
214
306
        event_data.edited_fields.indexOf("preview_diff") >= 0);
215
307
};
216
308
 
217
 
}, '0.1', {requires: ['node', 'lp.client', 'lp.anim']});
 
309
}, '0.1', {requires: ['node', 'lp.client', 'lp.anim',
 
310
                      'lp.code.branchmergeproposal.reviewcomment']});