From f71e9995a7f214cd16941855ec00b597ee107625 Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Tue, 24 Dec 2019 21:38:26 +0000 Subject: [PATCH] Dateless milestone work. Commit in preparation for merging forward. - Legacy-Id: 17174 --- .../externals/static/Sortable/Sortable.min.js | 2 + ietf/group/factories.py | 22 ++- .../0020_add_uses_milestone_dates.py | 26 +++ .../0021_add_order_to_milestones.py | 44 +++++ .../0022_populate_uses_milestone_dates.py | 30 +++ ietf/group/milestones.py | 183 +++++++++++------- ietf/group/models.py | 7 +- ietf/group/tests_info.py | 107 +++++++++- ietf/group/views.py | 6 +- ietf/static/ietf/css/ietf.css | 7 + ietf/static/ietf/js/edit-milestones.js | 66 +++++-- ietf/templates/group/edit_milestones.html | 125 +++++++----- ietf/templates/group/group_about.html | 8 +- ietf/templates/group/milestones.html | 68 ++++--- 14 files changed, 536 insertions(+), 165 deletions(-) create mode 100644 ietf/externals/static/Sortable/Sortable.min.js create mode 100644 ietf/group/migrations/0020_add_uses_milestone_dates.py create mode 100644 ietf/group/migrations/0021_add_order_to_milestones.py create mode 100644 ietf/group/migrations/0022_populate_uses_milestone_dates.py diff --git a/ietf/externals/static/Sortable/Sortable.min.js b/ietf/externals/static/Sortable/Sortable.min.js new file mode 100644 index 000000000..79898819a --- /dev/null +++ b/ietf/externals/static/Sortable/Sortable.min.js @@ -0,0 +1,2 @@ +/*! Sortable 1.10.1 - MIT | git://github.com/SortableJS/Sortable.git */ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Sortable=e()}(this,function(){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(){return(a=Object.assign||function(t){for(var e=1;e"===e[0]&&(e=e.substring(1)),t)try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch(t){return!1}return!1}}function P(t,e,n,o){if(t){n=n||document;do{if(null!=e&&(">"===e[0]?t.parentNode===n&&h(t,e):h(t,e))||o&&t===n)return t;if(t===n)break}while(t=(i=t).host&&i!==document&&i.host.nodeType?i.host:i.parentNode)}var i;return null}var f,p=/\s+/g;function k(t,e,n){if(t&&e)if(t.classList)t.classList[n?"add":"remove"](e);else{var o=(" "+t.className+" ").replace(p," ").replace(" "+e+" "," ");t.className=(o+(n?" "+e:"")).replace(p," ")}}function R(t,e,n){var o=t&&t.style;if(o){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(n=t.currentStyle),void 0===e?n:n[e];e in o||-1!==e.indexOf("webkit")||(e="-webkit-"+e),o[e]=n+("string"==typeof n?"":"px")}}function v(t,e){var n="";if("string"==typeof t)n=t;else do{var o=R(t,"transform");o&&"none"!==o&&(n=o+" "+n)}while(!e&&(t=t.parentNode));var i=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix;return i&&new i(n)}function g(t,e,n){if(t){var o=t.getElementsByTagName(e),i=0,r=o.length;if(n)for(;i=e.left-n&&r<=e.right+n,i=a>=e.top-n&&a<=e.bottom+n;return n&&o&&i?l=t:void 0}}),l}((t=t.touches?t.touches[0]:t).clientX,t.clientY);if(e){var n={};for(var o in t)t.hasOwnProperty(o)&&(n[o]=t[o]);n.target=n.rootEl=e,n.preventDefault=void 0,n.stopPropagation=void 0,e[j]._onDragOver(n)}}}function kt(t){z&&z.parentNode[j]._isOutsideThisEl(t.target)}function Rt(t,e){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(t));this.el=t,this.options=e=a({},e),t[j]=this;var n={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(t.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return Ot(t,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(t,e){t.setData("Text",e.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==Rt.supportPointer&&"PointerEvent"in window,emptyInsertThreshold:5};for(var o in O.initializePlugins(this,t,n),n)o in e||(e[o]=n[o]);for(var i in At(e),this)"_"===i.charAt(0)&&"function"==typeof this[i]&&(this[i]=this[i].bind(this));this.nativeDraggable=!e.forceFallback&&xt,this.nativeDraggable&&(this.options.touchStartThreshold=1),e.supportPointer?u(t,"pointerdown",this._onTapStart):(u(t,"mousedown",this._onTapStart),u(t,"touchstart",this._onTapStart)),this.nativeDraggable&&(u(t,"dragover",this),u(t,"dragenter",this)),bt.push(this.el),e.store&&e.store.get&&this.sort(e.store.get(this)||[]),a(this,T())}function Xt(t,e,n,o,i,r,a,l){var s,c,u=t[j],d=u.options.onMove;return!window.CustomEvent||w||E?(s=document.createEvent("Event")).initEvent("move",!0,!0):s=new CustomEvent("move",{bubbles:!0,cancelable:!0}),s.to=e,s.from=t,s.dragged=n,s.draggedRect=o,s.related=i||e,s.relatedRect=r||X(e),s.willInsertAfter=l,s.originalEvent=a,t.dispatchEvent(s),d&&(c=d.call(u,s,a)),c}function Yt(t){t.draggable=!1}function Bt(){Dt=!1}function Ft(t){for(var e=t.tagName+t.className+t.src+t.href+t.textContent,n=e.length,o=0;n--;)o+=e.charCodeAt(n);return o.toString(36)}function Ht(t){return setTimeout(t,0)}function Lt(t){return clearTimeout(t)}Rt.prototype={constructor:Rt,_isOutsideThisEl:function(t){this.el.contains(t)||t===this.el||(ht=null)},_getDirection:function(t,e){return"function"==typeof this.options.direction?this.options.direction.call(this,t,e,z):this.options.direction},_onTapStart:function(e){if(e.cancelable){var n=this,o=this.el,t=this.options,i=t.preventOnFilter,r=e.type,a=e.touches&&e.touches[0]||e.pointerType&&"touch"===e.pointerType&&e,l=(a||e).target,s=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||l,c=t.filter;if(function(t){_t.length=0;var e=t.getElementsByTagName("input"),n=e.length;for(;n--;){var o=e[n];o.checked&&_t.push(o)}}(o),!z&&!(/mousedown|pointerdown/.test(r)&&0!==e.button||t.disabled||s.isContentEditable||(l=P(l,t.draggable,o,!1))&&l.animated||Z===l)){if(J=F(l),et=F(l,t.draggable),"function"==typeof c){if(c.call(this,e,l,this))return W({sortable:n,rootEl:s,name:"filter",targetEl:l,toEl:o,fromEl:o}),K("filter",n,{evt:e}),void(i&&e.cancelable&&e.preventDefault())}else if(c&&(c=c.split(",").some(function(t){if(t=P(s,t.trim(),o,!1))return W({sortable:n,rootEl:t,name:"filter",targetEl:l,fromEl:o,toEl:o}),K("filter",n,{evt:e}),!0})))return void(i&&e.cancelable&&e.preventDefault());t.handle&&!P(s,t.handle,o,!1)||this._prepareDragStart(e,a,l)}}},_prepareDragStart:function(t,e,n){var o,i=this,r=i.el,a=i.options,l=r.ownerDocument;if(n&&!z&&n.parentNode===r){var s=X(n);if(q=r,G=(z=n).parentNode,V=z.nextSibling,Z=n,ot=a.group,rt={target:Rt.dragged=z,clientX:(e||t).clientX,clientY:(e||t).clientY},ct=rt.clientX-s.left,ut=rt.clientY-s.top,this._lastX=(e||t).clientX,this._lastY=(e||t).clientY,z.style["will-change"]="all",o=function(){K("delayEnded",i,{evt:t}),Rt.eventCanceled?i._onDrop():(i._disableDelayedDragEvents(),!c&&i.nativeDraggable&&(z.draggable=!0),i._triggerDragStart(t,e),W({sortable:i,name:"choose",originalEvent:t}),k(z,a.chosenClass,!0))},a.ignore.split(",").forEach(function(t){g(z,t.trim(),Yt)}),u(l,"dragover",Pt),u(l,"mousemove",Pt),u(l,"touchmove",Pt),u(l,"mouseup",i._onDrop),u(l,"touchend",i._onDrop),u(l,"touchcancel",i._onDrop),c&&this.nativeDraggable&&(this.options.touchStartThreshold=4,z.draggable=!0),K("delayStart",this,{evt:t}),!a.delay||a.delayOnTouchOnly&&!e||this.nativeDraggable&&(E||w))o();else{if(Rt.eventCanceled)return void this._onDrop();u(l,"mouseup",i._disableDelayedDrag),u(l,"touchend",i._disableDelayedDrag),u(l,"touchcancel",i._disableDelayedDrag),u(l,"mousemove",i._delayedDragTouchMoveHandler),u(l,"touchmove",i._delayedDragTouchMoveHandler),a.supportPointer&&u(l,"pointermove",i._delayedDragTouchMoveHandler),i._dragStartTimer=setTimeout(o,a.delay)}}},_delayedDragTouchMoveHandler:function(t){var e=t.touches?t.touches[0]:t;Math.max(Math.abs(e.clientX-this._lastX),Math.abs(e.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){z&&Yt(z),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var t=this.el.ownerDocument;d(t,"mouseup",this._disableDelayedDrag),d(t,"touchend",this._disableDelayedDrag),d(t,"touchcancel",this._disableDelayedDrag),d(t,"mousemove",this._delayedDragTouchMoveHandler),d(t,"touchmove",this._delayedDragTouchMoveHandler),d(t,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(t,e){e=e||"touch"==t.pointerType&&t,!this.nativeDraggable||e?this.options.supportPointer?u(document,"pointermove",this._onTouchMove):u(document,e?"touchmove":"mousemove",this._onTouchMove):(u(z,"dragend",this),u(q,"dragstart",this._onDragStart));try{document.selection?Ht(function(){document.selection.empty()}):window.getSelection().removeAllRanges()}catch(t){}},_dragStarted:function(t,e){if(vt=!1,q&&z){K("dragStarted",this,{evt:e}),this.nativeDraggable&&u(document,"dragover",kt);var n=this.options;t||k(z,n.dragClass,!1),k(z,n.ghostClass,!0),Rt.active=this,t&&this._appendGhost(),W({sortable:this,name:"start",originalEvent:e})}else this._nulling()},_emulateDragOver:function(){if(at){this._lastX=at.clientX,this._lastY=at.clientY,Nt();for(var t=document.elementFromPoint(at.clientX,at.clientY),e=t;t&&t.shadowRoot&&(t=t.shadowRoot.elementFromPoint(at.clientX,at.clientY))!==e;)e=t;if(z.parentNode[j]._isOutsideThisEl(t),e)do{if(e[j]){if(e[j]._onDragOver({clientX:at.clientX,clientY:at.clientY,target:t,rootEl:e})&&!this.options.dragoverBubble)break}t=e}while(e=e.parentNode);It()}},_onTouchMove:function(t){if(rt){var e=this.options,n=e.fallbackTolerance,o=e.fallbackOffset,i=t.touches?t.touches[0]:t,r=U&&v(U),a=U&&r&&r.a,l=U&&r&&r.d,s=Ct&>&&b(gt),c=(i.clientX-rt.clientX+o.x)/(a||1)+(s?s[0]-Et[0]:0)/(a||1),u=(i.clientY-rt.clientY+o.y)/(l||1)+(s?s[1]-Et[1]:0)/(l||1);if(!Rt.active&&!vt){if(n&&Math.max(Math.abs(i.clientX-this._lastX),Math.abs(i.clientY-this._lastY))o.right+10||t.clientX<=o.right&&t.clientY>o.bottom&&t.clientX>=o.left:t.clientX>o.right&&t.clientY>o.top||t.clientX<=o.right&&t.clientY>o.bottom+10}(n,a,this)&&!g.animated){if(g===z)return A(!1);if(g&&l===n.target&&(s=g),s&&(i=X(s)),!1!==Xt(q,l,z,o,s,i,n,!!s))return O(),l.appendChild(z),G=l,N(),A(!0)}else if(s.parentNode===l){i=X(s);var v,m,b,y=z.parentNode!==l,w=!function(t,e,n){var o=n?t.left:t.top,i=n?t.right:t.bottom,r=n?t.width:t.height,a=n?e.left:e.top,l=n?e.right:e.bottom,s=n?e.width:e.height;return o===a||i===l||o+r/2===a+s/2}(z.animated&&z.toRect||o,s.animated&&s.toRect||i,a),E=a?"top":"left",D=Y(s,"top","top")||Y(z,"top","top"),_=D?D.scrollTop:void 0;if(ht!==s&&(m=i[E],yt=!1,wt=!w&&e.invertSwap||y),0!==(v=function(t,e,n,o,i,r,a,l){var s=o?t.clientY:t.clientX,c=o?n.height:n.width,u=o?n.top:n.left,d=o?n.bottom:n.right,h=!1;if(!a)if(l&&pt 0 ); + var milestone_order_has_changed = false; // make sure we got the lowest number for idCounter milestonesForm.find('.edit-milestone input[name$="-id"]').each(function () { @@ -12,6 +14,7 @@ $(document).ready(function () { function setChanged() { $(this).closest(".edit-milestone").addClass("changed"); setSubmitButtonState(); + $("#switch-date-use-form").hide(); } milestonesForm.on("change", '.edit-milestone select,.edit-milestone input,.edit-milestone textarea', setChanged); @@ -23,7 +26,7 @@ $(document).ready(function () { function setSubmitButtonState() { var action, label; - if (milestonesForm.find("input[name$=delete]:visible").length > 0) + if ( milestonesForm.find("input[name$=delete]:visible").length > 0 || milestone_order_has_changed ) action = "review"; else action = "save"; @@ -58,18 +61,25 @@ $(document).ready(function () { }); milestonesForm.find(".add-milestone").click(function() { - // move Add milestone row and duplicate hidden template - var row = $(this).closest("tr"), editRow = row.next(".edit-milestone"); - row.closest("table").append(row).append(editRow.clone()); + var template = $("#extratemplatecontainer .extratemplate"); + var templateclone = template.clone(); + $("#dragdropcontainer").append(templateclone); + var new_milestone = $("#dragdropcontainer > div:last") + var new_edit_milestone = new_milestone.find(".edit-milestone"); + var new_edit_milestone_order = $("#dragdropcontainer > div").length + + new_milestone.removeClass("extratemplate") + new_milestone.addClass("draggable") + new_milestone.addClass("milestonerow") - // fixup template var newId = idCounter; --idCounter; var prefix = "m" + newId; - editRow.find('input[name="prefix"]').val(prefix); + new_edit_milestone.find('input[name="prefix"]').val(prefix); + new_edit_milestone.find('input[name="order"]').val(new_edit_milestone_order); - editRow.find("input,select,textarea").each(function () { + new_edit_milestone.find("input,select,textarea").each(function () { if (this.name == "prefix") return; @@ -79,17 +89,21 @@ $(document).ready(function () { this.name = prefix + "-" + this.name; this.id = prefix + "-" + this.id; }); - editRow.find("label").each(function () { + new_edit_milestone.find("label").each(function () { if (this.htmlFor) this.htmlFor = prefix + "-" + this.htmlFor; }); - editRow.removeClass("template"); - editRow.show(); + new_edit_milestone.removeClass("template"); + new_edit_milestone.show(); - editRow.find(".select2-field").each(function () { + new_edit_milestone.find(".select2-field").each(function () { window.setupSelect2Field($(this)); // from ietf.js }); + + if ( ! group_uses_milestone_dates ) { + setOrderControlValue(); + } }); function setResolvedState() { @@ -129,6 +143,13 @@ $(document).ready(function () { } } + function setOrderControlValue() { + $("#dragdropcontainer > div").each(function(index){ + var prefix = $(this).find('input[name="prefix"]').val(); + $(this).find('input[name="'+prefix+'-order"]').val(index) + }) + } + milestonesForm.find(".edit-milestone [name$=delete]").each(setDeleteState); milestonesForm.on("change", ".edit-milestone input[name$=delete]", setDeleteState); @@ -137,4 +158,25 @@ $(document).ready(function () { }); setSubmitButtonState(); -}); + + if ( ! group_uses_milestone_dates) { + setOrderControlValue(); + + function onEnd(event) { + milestone_order_has_changed = true; + setSubmitButtonState(); + setOrderControlValue(); + $("#switch-date-use-form").hide(); + + } + + var options = { + animation: 150, + draggable: ".draggable", + onEnd: function(event) {onEnd(event)} + }; + + var el = document.getElementById('dragdropcontainer'); + var sortable = new Sortable(el, options); + } +}); \ No newline at end of file diff --git a/ietf/templates/group/edit_milestones.html b/ietf/templates/group/edit_milestones.html index b35987843..88dff03e3 100644 --- a/ietf/templates/group/edit_milestones.html +++ b/ietf/templates/group/edit_milestones.html @@ -25,64 +25,83 @@ {% endif %}

+
+
+
{% csrf_token %} + +
+
-

- {% if forms %}Click a milestone to edit it.{% endif %} - {% if needs_review %} - Note that as {{ group.type.name }} Chair you cannot edit descriptions of existing - milestones and milestones you add are subject to review by the {{ reviewer }}. - {% endif %} -

+
+

+ {% if forms %}Click a milestone to edit it.{% endif %} + {% if forms and not group.uses_milestone_dates %}Drag and drop milestones to reorder them.{% endif %} - {% if can_reset %} -

- You can reset - this list to the milestones currently in use for the {{ group.acronym }} {{ group.type.name }}. -

- {% endif %} + {% if needs_review %} + Note that as {{ group.type.name }} Chair you cannot edit descriptions of existing + milestones and milestones you add are subject to review by the {{ reviewer }}. + {% endif %} +

- {% if form_errors %} -

There were errors, see below.

- {% endif %} + {% if can_reset %} +

+ You can reset + this list to the milestones currently in use for the {{ group.acronym }} {{ group.type.name }}. +

+ {% endif %} + + {% if form_errors %} +

There were errors, see below.

+ {% endif %} +
+
{% csrf_token %} - +
- {% for form in forms %} -
- - - + {% for form in forms %} +
+ + + {% if form.milestone.resolved %} + {{ form.milestone.resolved }} + {% else %} + {% if group.uses_milestone_dates %}{{ form.milestone.due|date:"M Y" }}{% endif %} + {% endif %} + + + {{ form.milestone.desc }} + {% if form.needs_review %}Awaiting accept{% endif %} + {% if form.changed %}Changed{% endif %} + {% if form.delete.data %}Deleted{% endif %} + + + {% for d in form.docs_names %} +
{{ d }}
+ {% endfor %} +
+
-
- - - {% endfor %} + + {% include "group/milestone_form.html" %} + + + {% endfor %} + +
+
+
+
+
+
+
{% include "group/milestone_form.html" with form=empty_form %}
+
+
- - - - - - -
- {% if form.milestone.resolved %} - {{ form.milestone.resolved }} - {% else %} - {{ form.milestone.due|date:"M Y" }} - {% endif %} - -
{{ form.milestone.desc }} - {% if form.needs_review %}Awaiting accept{% endif %} - {% if form.changed %}Changed{% endif %} - {% if form.delete.data %}Deleted{% endif %} -
- - {% for d in form.docs_names %} -
{{ d }}
- {% endfor %} -
{% include "group/milestone_form.html" %}
{% include "group/milestone_form.html" with form=empty_form %}
+ {% buttons %} Cancel @@ -92,11 +111,19 @@ {% endbuttons %}
+ + {% if group.uses_milestone_dates %} +
+ {% endif %} + {% endblock %} {% block js %} + {% if not group.uses_milestone_dates %} + + {% endif %} {% endblock %} diff --git a/ietf/templates/group/group_about.html b/ietf/templates/group/group_about.html index 236e8d342..3b61566a2 100644 --- a/ietf/templates/group/group_about.html +++ b/ietf/templates/group/group_about.html @@ -237,13 +237,7 @@ {% endif %} {% if group.features.has_milestones %} -

- {% if group.state_id == "proposed" %} - Proposed milestones - {% else %} - Milestones - {% endif %} -

+ {% include "group/milestones.html" with milestones=group.milestones %} {% if milestones_in_review %} diff --git a/ietf/templates/group/milestones.html b/ietf/templates/group/milestones.html index 1836459ef..72ce605f1 100644 --- a/ietf/templates/group/milestones.html +++ b/ietf/templates/group/milestones.html @@ -1,29 +1,45 @@ {# Copyright The IETF Trust 2015, All Rights Reserved #}{% load origin %}{% origin %} -{# assumes milestones is in context #} - - - - - - - - - {% for milestone in milestones reversed %} +{# assumes group and milestones is in context #} +{% regroup milestones by resolved as milestonegroups %} + +{% for milestoneset in milestonegroups %} +

+ {% if milestoneset.grouper %} + {{milestoneset.grouper}} milestones + {% else %} + {% if group.state_id == "proposed" %}Proposed milestones{% else %}Milestones{% endif %} + {% endif %} +

+
DateMilestone
+ - - + + - {% endfor %} - -
- {% if milestone.resolved %} - {{ milestone.resolved }} - {% else %} - {{ milestone.due|date:"M Y" }} - {% endif %} - - {{ milestone.desc }} - {% for d in milestone.docs.all %} -
{{ d.name }} - {% endfor %} -
{% if group.uses_milestone_dates %}Date{% else %}Order{% endif %}Milestone
+ + + {% for milestone in milestoneset.list reversed %} + + + {% if milestone.resolved %} + {{ milestone.resolved }} + {% else %} + {% if group.uses_milestone_dates %} + {{ milestone.due|date:"M Y" }} + {% else %} + {% if forloop.first %}Last{% endif %} + {% if forloop.last %}Next{% endif %} + {% endif %} + {% endif %} + + + {{ milestone.desc }} + {% for d in milestone.docs.all %} +
{{ d.name }} + {% endfor %} + + + {% endfor %} + + +{% endfor %}