mtrack /web/plan.php

Language PHP Lines 341
MD5 Hash 37afaf1f99575e207326c9bb0743ac62 Estimated Cost $7,739 (why?)
Repository https://bitbucket.org/yoander/mtrack View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<?php # vim:ts=2:sw=2:et:
/* For copyright and licensing terms, see the file named LICENSE */

include '../inc/common.php';
$pi = urldecode(mtrack_get_pathinfo());

if (!strlen($pi)) {
  throw new Exception("no milestone specified");
}

MTrackACL::requireAllRights("Roadmap", 'modify');

$MS = MTrackAPI::invoke('GET', "/milestone/$pi")->result;

if (!$MS) {
  throw new Exception("no such milestone $pi");
}
mtrack_head("$MS->name - Planning");

$MS = json_encode($MS);

$milestones = MTrackAPI::invoke('GET', '/milestones')->result;
$ALL_MS = array();
foreach ($milestones as $M) {
  if ($M->id == $ms->mid) continue;
  $m = new stdclass;
  $m->id = $M->id;
  $m->label = $M->name;
  $ALL_MS[] = $m;
}
$ALL_MS = json_encode($ALL_MS);

echo <<<HTML
<div id='plan-banner'>
  <h1 id='milestone-name'></h1>
  <div id="plan-milestone-other-selector"></div>
  <div id='plan-rsrc-summary'>
    Allocation
    <span id='plan-rsrc-total'></span>
    hours
  </div>
  <br>
  <button id='newtkt' class='btn btn-primary'><i class='icon-white icon-plus'></i>New Ticket</button>
</div>
<div id="plan-milestone-area">
  <div id="plan-ticket-list"></div>
  <div id="plan-ticket-other"></div>
  <div id="plan-rsrc-list"></div>
</div>

<script type="text/template" id='ticket-template'>
<div class='handle'>
  <div class='summary'>
  <% if (status == 'closed') { %><del><% } %>
  <% if (nsident) { %>#<%- nsident %><% } else { %>[NEW]<% } %> <%- summary %>
  <% if (status == 'closed') { %></del><% } %>
  </div>
  <% if (remaining) { %>
    <span class='loe'><%- remaining %></span>
  <% } %>
    <button class='btn btn-mini'><i class='icon-plus'></i></button>
  <% if (owner) { %>
    <img class='gravatar' src="${ABSWEB}avatar.php?u=<%- owner %>&amp;s=32">
  <% } %>
</div>
</script>

<script type="text/template" id="rsrc-template">
<div class='allocated-resource'>
  <img class='gravatar' src="${ABSWEB}avatar.php?u=<%- owner %>&amp;s=32">
  <%- owner %>
  <span class='loe'><%- total %></span>
</div>
</script>

<div id='tktdialog' class='modal hide'>
  <div class='modal-header'>
    <a class='close' data-dismiss='modal'>&times;</a>
    <h3><span id='tkttitle'></span>
      <span id='tktsummary'></span>
    </h3>
  </div>
  <div class='modal-body'>
  <div id='tktdesc'></div>
  </div>
  <div class='modal-footer'>
    <button class='btn' id='edittktdesc'
      ><i class='icon-pencil'></i> Edit Description</button>
    <button class='btn' data-dismiss='modal'>Cancel</button>
    <button type='submit' class='btn btn-primary'>Save</button>
  </div>
  </form>
</div>

<script>
$(document).ready(function () {
  var TheMilestone = new MTrackMilestone($MS);
  var ALL_MS = $ALL_MS;
  var OtherTicketList = null;

  var sel = $('<select/>', {
    "data-placeholder": "Select other milestone"
  });
  $('#plan-milestone-other-selector').append(sel);
  /* popover would be nice, but it craps out when used on a
   * position:fixed element */
  /*
  $('#plan-milestone-other-selector').popover({
    title: 'Source Milestone',
    placement: 'bottom',
    trigger: 'hover',
    content: 'Choose a second milestone to have its tickets display below.  You may then drag tickets between the milestones to move them'
});
   */
  sel.append("<option value=''></option>");
  _.each(ALL_MS, function (ms) {
    if (ms.id == TheMilestone.id) {
      return;
    }
    var opt = $("<option/>");
    opt.attr('value', ms.id);
    opt.text(ms.label);
    sel.append(opt);
  });
  sel.chosen({
    allow_single_deselect: true
  }).change(function() {
    var msid = sel.val();
    if (OtherTicketList) {
      delete OtherTicketList;
      $('#plan-ticket-other').empty();
      OtherTicketList = null;
    }

    if (msid) {
      var m = new MTrackMilestone({id: msid});
      m.fetch({success: function(model, response) {
        OtherTicketList = new MTrackPlanningTicketListView({
          el: '#plan-ticket-other',
          model: model
        });
      }});
    }
    $(document.body).animate({scrollTop: 0}, {
      duration: 300,
      easing: "easeOutQuint"
    });
  });

  /*
  new MTrackClickToEditTextField({
    model: TheMilestone,
    srcattr: "name",
    el: "#milestone-name",
    readonly: true,
    saveAfterEdit: true
  });
  TheMilestone.bind('change', function () {
    $('html head title').text(TheMilestone.get('name') + " - Planning");
});
  */
  $('#milestone-name').text('Planning: ' + TheMilestone.get('name'));
  var plv = new MTrackPlanningTicketListView({
    model: TheMilestone,
    el: '#plan-ticket-list'
  });

  var alloc_timer = null;

  function update_allocation() {
    if (alloc_timer) {
      return;
    }
    alloc_timer = setTimeout(function () {
      $.ajax({
        url: ABSWEB + "api.php/milestone/" + TheMilestone.id + "/time/remaining",
        success: function(data) {
          var r = $('#plan-rsrc-total');
          r.text(data.total);

          r = $('#plan-rsrc-list');
          r.empty();
          var template = _.template($('#rsrc-template').html());
          _.each(_.keys(data.users).sort(), function(u) {
            var t = Math.round(100 * data.users[u]) / 100;
            var d = $(template({owner: u, total: t}));
            r.append(d);
          });

          r.append($(template({
            owner: 'Unassigned',
            total: data.unassigned
          })));

          r.popover({
            title: 'Resource Allocation',
            trigger: 'hover',
            placement: 'left',
            content: 'This area shows resource allocation broken out by user.  It only includes tickets that have time remaining.  The sum of remaining time for tickets that are not assigned is shown at the bottom of this list.'
          });
        },
        complete: function() {
          alloc_timer = null;
        }
      });
    }, 200);
  }

  TheMilestone.tickets.bind('all', function () {
    update_allocation();
  });

  var fake_ticket = new MTrackTicket;
  var wiki = null;
  var summary_editor = null;
  var on_ticket_save = null;

  /* set stuff up for ticket editing */
  function setup_ticket_editor() {
    var M = $('#tktdialog');
    summary_editor = new MTrackClickToEditTextField({
        model: fake_ticket,
        srcattr: "summary",
        el: "#tktsummary",
        placeholder: "Enter ticket summary"
    });
    //$('#tktdesc').html(T.get('description_html'));
    wiki = new MTrackWikiTextAreaView({
        model: fake_ticket,
        wikiContext: "ticket:",
        use_overlay: true,
        Caption: "Edit Description",
        OKLabel: "Accept Description",
        CancelLabel: "Abandon changes to description",
        srcattr: "description",
        renderedattr: "description_html",
        el: "#tktdesc"
    });
    wiki.bind('editstart', function () {
      setTimeout(function () {
        M.modal('hide');
      }, 1000);
    });
    wiki.bind('editend', function () {
      M.modal('show');
    });
    $('#edittktdesc').click(function () {
      wiki.edit();
    });
    $('#tktdialog button[type=submit]').click(function () {
      on_ticket_save();
    });

  };
  setup_ticket_editor();

  function show_ticket_editor(T, after) {
    var M = $('#tktdialog');

    fake_ticket.set({
      summary: T.get('summary'),
      description_html: T.get('description_html'),
      description: T.get('description')
    });//, {silent: true});
    //wiki.change();

    $('#tkttitle').text(
      T.id ?
        ( 'Edit Ticket #' + T.get('nsident') ) :
        'New Ticket'
    );
    on_ticket_save = function() {
      // Apply changes from the clone
      T.save({
        summary: fake_ticket.get('summary'),
        description: fake_ticket.get('description'),
        description_html: fake_ticket.get('description_html')
      }, {
        success: function() {
          after.success();
        }
      });
      M.modal('hide');
    };

    M.modal();
  };

  $('#plan-ticket-list, #plan-ticket-other')
      .on('dblclick', 'div.handle', function() {
    var T = $(this.parentElement).data('plan-tkt');
    show_ticket_editor(T, {
      success: function () {
      }
    });
  });
  /* show nice data augments via popovers */
  $('#plan-ticket-list, #plan-ticket-other').popover({
    selector: 'div.handle',
    title: function() {
      var T = $(this.parentElement).data('plan-tkt');
      return T.get('summary');
    },
    placement: function() {
      var ele = this.\$element;
      return ele.parents().filter('#plan-ticket-list').length > 0 ?
        'right' : 'left';
    },
    content: function() {
      var T = $(this.parentElement).data('plan-tkt');
      var html = '';
      if (T.get('owner')) {
        html += "<b>Owner:</b> " + T.get("owner") + "<br>";
      }
      html += "<b>Type:</b> " + T.get("classification") + "<br>";
      html += "<b>Status:</b> " + T.get("status");

      return html;
    }
  });

  $('#newtkt').click(function() {
    var T = new MTrackTicket;
    var m = {};
    m[TheMilestone.id] = TheMilestone.get('name');
    T.set({milestones: m, classification: 'enhancement'}, {silent: true});
    show_ticket_editor(T, {
      success: function () {
        // TODO: add to collection
        TheMilestone.tickets.add(T, {at: TheMilestone.tickets.length});
      }
    });
  });


});
</script>
HTML;

mtrack_foot();
Back to Top