Browse Source

on its way

amadilsons 7 years ago
parent
commit
089dbf0cf6

+ 4 - 1
client/components/lists/list.styl

@@ -113,7 +113,7 @@
 
 
 #js-wip-limit-edit
 #js-wip-limit-edit
   padding-top: 2%
   padding-top: 2%
-  
+
   p
   p
     margin-bottom: 0
     margin-bottom: 0
 
 
@@ -123,3 +123,6 @@
   .wip-limit-value
   .wip-limit-value
     width: 20%
     width: 20%
     margin-right: 5%
     margin-right: 5%
+
+  .wip-limit-error
+    display: none

+ 20 - 6
client/components/lists/listHeader.jade

@@ -6,9 +6,9 @@ template(name="listHeader")
       h2.list-header-name(
       h2.list-header-name(
         class="{{#if currentUser.isBoardMember}}js-open-inlined-form is-editable{{/if}}")
         class="{{#if currentUser.isBoardMember}}js-open-inlined-form is-editable{{/if}}")
         = title
         = title
-        if hasWipLimit
+        if isWipLimitEnabled
           span
           span
-            | (#{wipLimit})
+            | (#{wipLimit.value})
         if showCardsCountForList cards.count
         if showCardsCountForList cards.count
           = cards.count
           = cards.count
           span.lowercase
           span.lowercase
@@ -37,7 +37,7 @@ template(name="listActionPopup")
         li: a.js-select-cards {{_ 'list-select-cards'}}
         li: a.js-select-cards {{_ 'list-select-cards'}}
         hr
         hr
     ul.pop-over-list
     ul.pop-over-list
-      li: a.js-set-wip-limit {{#if hasWipLimit}}{{_ 'edit-wip-limit'}}{{else}}{{_ 'setWipLimitPopup-title'}}{{/if}}
+      li: a.js-set-wip-limit {{#if isWipLimitEnabled }}EDIT{{else}}{{_ 'setWipLimitPopup-title'}}{{/if}}
     hr
     hr
     ul.pop-over-list
     ul.pop-over-list
       li: a.js-close-list {{_ 'archive-list'}}
       li: a.js-close-list {{_ 'archive-list'}}
@@ -74,6 +74,20 @@ template(name="listDeletePopup")
 template(name="setWipLimitPopup")
 template(name="setWipLimitPopup")
   #js-wip-limit-edit
   #js-wip-limit-edit
     lable {{_ 'set-wip-limit-value'}}
     lable {{_ 'set-wip-limit-value'}}
-    p
-      input.wip-limit-value(type="number" value="#{wipLimit}" min="0" max="99" onkeydown="return false")
-      input.wip-limit-apply(type="submit" value="{{_ 'apply'}}")
+    {{one}}
+    ul.pop-over-list
+      li: a.js-enable-wip-limit Enable WIP Limit 
+        if isWipLimitEnabled  
+          i.fa.fa-check
+          
+    if isWipLimitEnabled
+      p
+        input.wip-limit-value(type="number" value="#{wipLimit.value}" min="1" max="99" onkeydown="return false")
+        input.wip-limit-apply(type="submit" value="{{_ 'apply'}}")
+        input.wip-limit-error
+        
+template(name="wipLimitErrorPopup")
+  .wip-limit-invalid
+    p The number of tasks in this list is higher than the WIP limit you've defined.
+    p Please move some tasks out of this list, or set a higher WIP limit.
+    button.full.js-back-view(type="submit") {{_ 'cancel'}}

+ 71 - 6
client/components/lists/listHeader.js

@@ -8,8 +8,9 @@ BlazeComponent.extendComponent({
     }
     }
   },
   },
 
 
-  hasWipLimit() {
-    return this.currentData().wipLimit > 0 ? true : false;
+  isWipLimitEnabled() {
+    const limit = this.currentData().wipLimit
+    return limit.enabled && limit.value > 0;
   },
   },
 
 
   isWatching() {
   isWatching() {
@@ -41,10 +42,9 @@ BlazeComponent.extendComponent({
 }).register('listHeader');
 }).register('listHeader');
 
 
 Template.listActionPopup.helpers({
 Template.listActionPopup.helpers({
-  hasWipLimit() {
-    return this.wipLimit > 0 ? true : false;
+  isWipLimitEnabled() {
+    return Lists.findOne(this.data()._id, { 'wipLimit.enabled': 1 }).wipLimit.enabled;
   },
   },
-
   isWatching() {
   isWatching() {
     return this.findWatcher(Meteor.userId());
     return this.findWatcher(Meteor.userId());
   },
   },
@@ -73,12 +73,77 @@ Template.listActionPopup.events({
   'click .js-more': Popup.open('listMore'),
   'click .js-more': Popup.open('listMore'),
 });
 });
 
 
+Template.setWipLimitPopup.helpers({
+  one() {
+    //console.log(this)
+    //console.log(Template.instance())
+  }
+});
+
+BlazeComponent.extendComponent({
+  onCreated() {
+    this.wipEnabled = new ReactiveVar(Template.currentData().wipLimit.enabled);
+  },
+
+  toggleWipEnabled() {
+    const list = Lists.findOne(this.data()._id);
+    list.wipLimit.enabled ? list.setWipLimitDisabled() : list.setWipLimitEnabled()
+  },
+
+  isWipLimitEnabled() {
+    return Lists.findOne(this.data()._id, { 'wipLimit.enabled': 1 }).wipLimit.enabled;
+  },
+  events() {
+    return [{
+      'click .js-enable-wip-limit'(_, instance) {
+        //By default wipLimit.enabled is false or undefined. First click will always be to enable wip limiting
+        this.wipEnabled.set(!this.wipEnabled.get());
+        //console.log(Template.parentData(2))
+        //Template.parentData(2).data.toggleWipLimit(!Template.currentData().wipLimit.enabled); //If wipLimit.enabled is not yet definied, the negation of "undefined" is "true"
+        this.toggleWipEnabled()
+      },
+      'click .wip-limit-apply'(_, instance) {
+        const list = Template.currentData();
+        const limit = Template.instance().$('.wip-limit-value').val();
+
+        if(limit < list.allCards().count()){
+          Template.instance().$('.wip-limit-error').click();
+        } else {
+          list.setWipLimit(limit);
+        }
+      },
+      'click .wip-limit-error': Popup.open('wipLimitError'),
+    }];
+  },
+}).register('setWipLimitPopup');
+
+
+/*
+Template.setWipLimitPopup.helpers({
+  isWipLimitEnabled(instance) {
+    console.log(this);
+    console.log(Template.currentData());
+    console.log(instance);
+    return Template.currentData().wipLimit.enabled;
+  },
+});
+
 Template.setWipLimitPopup.events({
 Template.setWipLimitPopup.events({
+  'click .js-enable-wip-limit'(_, instance) {
+    //By default wipLimit.enabled is false or undefined. First click will always be to enable wip limiting
+    instance.wipEnabled.set(!instance.wipEnabled.get())
+  //  list.toggleWipLimit(!list.wipLimit.enabled); //If wipLimit.enabled is not yet definied, the negation of "undefined" is "true"
+  },
   'click .wip-limit-apply'(_, instance) {
   'click .wip-limit-apply'(_, instance) {
     const limit = instance.$('.wip-limit-value').val();
     const limit = instance.$('.wip-limit-value').val();
+    if(limit < this.allCards().count()){
+      instance.$('.wip-limit-error').click(); //open popup with invisible button click
+      return;
+    }
     this.setWipLimit(limit);
     this.setWipLimit(limit);
   },
   },
-});
+  'click .wip-limit-error': Popup.open('wipLimitError'),
+});*/
 
 
 Template.listMorePopup.events({
 Template.listMorePopup.events({
   'click .js-delete': Popup.afterConfirm('listDelete', function () {
   'click .js-delete': Popup.afterConfirm('listDelete', function () {

+ 1 - 0
i18n/en-GB.i18n.json

@@ -349,6 +349,7 @@
     "welcome-list1": "Basics",
     "welcome-list1": "Basics",
     "welcome-list2": "Advanced",
     "welcome-list2": "Advanced",
     "what-to-do": "What do you want to do?",
     "what-to-do": "What do you want to do?",
+    "wipLimitErrorPopup-title": "Invalid WIP Limit",
     "admin-panel": "Admin Panel",
     "admin-panel": "Admin Panel",
     "settings": "Settings",
     "settings": "Settings",
     "people": "People",
     "people": "People",

+ 1 - 0
i18n/en.i18n.json

@@ -349,6 +349,7 @@
     "welcome-list1": "Basics",
     "welcome-list1": "Basics",
     "welcome-list2": "Advanced",
     "welcome-list2": "Advanced",
     "what-to-do": "What do you want to do?",
     "what-to-do": "What do you want to do?",
+    "wipLimitErrorPopup-title": "Invalid WIP Limit",
     "admin-panel": "Admin Panel",
     "admin-panel": "Admin Panel",
     "settings": "Settings",
     "settings": "Settings",
     "people": "People",
     "people": "People",

+ 1 - 0
i18n/pt-BR.i18n.json

@@ -349,6 +349,7 @@
     "welcome-list1": "Básico",
     "welcome-list1": "Básico",
     "welcome-list2": "Avançado",
     "welcome-list2": "Avançado",
     "what-to-do": "O que você gostaria de fazer?",
     "what-to-do": "O que você gostaria de fazer?",
+    "wipLimitErrorPopup-title": "Limite WIP Inválido",
     "admin-panel": "Painel Administrativo",
     "admin-panel": "Painel Administrativo",
     "settings": "Configurações",
     "settings": "Configurações",
     "people": "Pessoas",
     "people": "Pessoas",

+ 27 - 1
models/lists.js

@@ -43,9 +43,22 @@ Lists.attachSchema(new SimpleSchema({
     },
     },
   },
   },
   wipLimit: {
   wipLimit: {
+    type: Object,
+    optional: true,
+  },
+  "wipLimit.value": {
     type: SimpleSchema.Integer,
     type: SimpleSchema.Integer,
     optional: true,
     optional: true,
   },
   },
+  "wipLimit.enabled":{
+    type: Boolean,
+    autoValue() {
+      if(this.isInsert){
+        return false;
+      }
+    },
+    optional: true,
+  },
 }));
 }));
 
 
 Lists.allow({
 Lists.allow({
@@ -91,8 +104,21 @@ Lists.mutations({
     return { $set: { archived: false } };
     return { $set: { archived: false } };
   },
   },
 
 
+  toggleWipLimit(toggle) {
+    console.log("toggle " + this.wipLimit.enabled)
+    return { $set: { "wipLimit.enabled": !this.wipLimit.enabled } };
+  },
+
+  setWipLimitEnabled() {
+    return { $set: { "wipLimit.enabled": true } };
+  },
+
+  setWipLimitDisabled() {
+    return { $set: { "wipLimit.enabled": false } };
+  },
+
   setWipLimit(limit) {
   setWipLimit(limit) {
-    return { $set: { wipLimit: limit } };
+    return { $set: { "wipLimit.value": limit } };
   },
   },
 });
 });