Browse Source

My Cards development

first prototype
John R. Supplee 4 years ago
parent
commit
077e78d37c

+ 29 - 0
client/components/main/myCards.jade

@@ -0,0 +1,29 @@
+template(name="myCardsHeaderBar")
+  h1
+    a.back-btn(href="{{pathFor 'home'}}")
+      i.fa.fa-chevron-left
+    | {{_ 'my-cards'}}
+
+template(name="myCardsModalTitle")
+  h2
+    i.fa.fa-keyboard-o
+    | {{_ 'my-cards'}}
+
+template(name="myCards")
+  .wrapper
+    h2 User Id
+    p= userId
+    //p= query.assignees
+    h1 My Cards
+    each board in cardsFind
+      .board-title
+        = board.title
+      each swimlane in board.swimlanes
+        .swimlane-title
+          = swimlane.title
+        each list in swimlane.lists
+          .list-title
+            = list.title
+          each card in list.cards
+            .card-details-title
+              = card.title

+ 152 - 0
client/components/main/myCards.js

@@ -0,0 +1,152 @@
+const subManager = new SubsManager();
+// import Cards from '../../../models/cards';
+Meteor.subscribe('myCards');
+Meteor.subscribe('mySwimlanes');
+Meteor.subscribe('myLists');
+
+Template.myCardsHeaderBar.events({
+  'click .js-open-archived-board'() {
+    Modal.open('archivedBoards');
+  },
+});
+
+Template.myCardsHeaderBar.helpers({
+  title() {
+    return FlowRouter.getRouteName() === 'home' ? 'my-boards' : 'public';
+  },
+  templatesUser() {
+    return Meteor.user();
+  },
+});
+
+Template.myCards.helpers({
+  userId() {
+    return Meteor.userId();
+  },
+});
+
+BlazeComponent.extendComponent({
+  onCreated() {
+    Meteor.subscribe('setting');
+    // subManager.subscribe('myCards');
+  },
+
+  boards() {
+    boards = [];
+    const cursor = Boards.find({
+      archived: false,
+      'members.userId': Meteor.userId(),
+      type: 'board',
+    });
+
+    return cursor;
+  },
+
+  cardsFind() {
+    const boards = [];
+    let board = null;
+    let swimlane = null;
+    let list = null;
+
+    const cursor = Cards.find(
+      {
+        // archived: false,
+        // $or: [{ members: userId }, { assignees: userId }],
+      },
+      {
+        sort: {
+          boardId: 1,
+          swimlaneId: 1,
+          listId: 1,
+          sort: 1,
+        },
+      },
+    );
+    // eslint-disable-next-line no-console
+    console.log('cursor:', cursor);
+    // let card = null;
+    // if (cursor.hasNext()) {
+    //   card = cursor.next();
+    // }
+
+    let newBoard = false;
+    let newSwimlane = false;
+    let newList = false;
+
+    cursor.forEach(card => {
+      // eslint-disable-next-line no-console
+      console.log('card:', card.title);
+      if (list === null || list.id !== card.listId) {
+        // eslint-disable-next-line no-console
+        console.log('new list');
+        let l = Lists.findOne(card.listId);
+        if (!l) {
+          l = {
+            _id: card.listId,
+            title: 'undefined list',
+          };
+        }
+        // eslint-disable-next-line no-console
+        console.log('list:', l);
+        list = {
+          id: l._id,
+          title: l.title,
+          cards: [card],
+        };
+        newList = true;
+      }
+      if (swimlane === null || card.swimlaneId !== swimlane.id) {
+        // eslint-disable-next-line no-console
+        console.log('new swimlane');
+        let s = Swimlanes.findOne(card.swimlaneId);
+        if (!s) {
+          s = {
+            _id: card.swimlaneId,
+            title: 'undefined swimlane',
+          };
+        }
+        // eslint-disable-next-line no-console
+        console.log('swimlane:', s);
+        swimlane = {
+          id: s._id,
+          title: s.title,
+          lists: [list],
+        };
+        newSwimlane = true;
+      }
+      if (board === null || card.boardId !== board.id) {
+        // eslint-disable-next-line no-console
+        console.log('new board');
+        const b = Boards.findOne(card.boardId);
+        // eslint-disable-next-line no-console
+        console.log('board:', b, b._id, b.title);
+        board = {
+          id: b._id,
+          title: b.title,
+          swimlanes: [swimlane],
+        };
+        newBoard = true;
+      }
+
+      if (newBoard) {
+        boards.push(board);
+      } else if (newSwimlane) {
+        board.swimlanes.push(swimlane);
+      } else if (newList) {
+        swimlane.lists.push(list);
+      } else {
+        list.cards.push(card);
+      }
+
+      // card = cursor.hasNext() ? cursor.next() : null;
+
+      newBoard = false;
+      newSwimlane = false;
+      newList = false;
+    });
+
+    // eslint-disable-next-line no-console
+    console.log('boards:', boards);
+    return boards;
+  },
+}).register('myCards');

+ 35 - 0
client/components/main/myCards.styl

@@ -0,0 +1,35 @@
+.my-cards-list
+  .my-cards-list-item
+    border-bottom: 1px solid darken(white, 25%)
+    padding: 10px 5px
+
+    &:last-child
+      border-bottom: none
+
+    .my-cards-list-item-keys
+      margin-top: 5px
+      float: right
+
+      kbd
+        padding: 5px 8px
+        margin: 5px
+        font-size: 18px
+
+    .my-cards-list-item-action
+      font-size: 1.4em
+      margin: 5px
+
+.board-title
+  font-size: 1.4em
+  font-weight: bold
+
+.swimlane-title
+  font-size: 1.2em
+  font-weight: bold
+  margin-left: 1em
+  margin-top: 10px
+
+.list-title
+  margin-top: 5px
+  font-weight: bold
+  margin-left: 2em

+ 26 - 0
config/router.js

@@ -113,6 +113,32 @@ FlowRouter.route('/shortcuts', {
   },
   },
 });
 });
 
 
+FlowRouter.route('/my-cards', {
+  name: 'my-cards',
+  action() {
+    const myCardsTemplate = 'myCards';
+
+    Filter.reset();
+    // EscapeActions.executeAll();
+    EscapeActions.executeUpTo('popup-close');
+
+    Utils.manageCustomUI();
+    Utils.manageMatomo();
+
+    if (previousPath) {
+      Modal.open(myCardsTemplate, {
+        header: 'myCardsModalTitle',
+        onCloseGoTo: previousPath,
+      });
+    } else {
+      BlazeLayout.render('defaultLayout', {
+        headerBar: 'myCardsHeaderBar',
+        content: myCardsTemplate,
+      });
+    }
+  },
+});
+
 FlowRouter.route('/import/:source', {
 FlowRouter.route('/import/:source', {
   name: 'import',
   name: 'import',
   triggersEnter: [AccountsTemplates.ensureSignedIn],
   triggersEnter: [AccountsTemplates.ensureSignedIn],

+ 60 - 0
server/publications/boards.js

@@ -42,6 +42,66 @@ Meteor.publish('boards', function() {
   );
   );
 });
 });
 
 
+Meteor.publish('mySwimlanes', function() {
+  const userId = this.userId;
+  const swimlanes = [];
+
+  Cards.find({
+    archived: false,
+    $or: [{ members: userId }, { assignees: userId }],
+  }).forEach(card => {
+    swimlanes.push(card.swimlaneId);
+  });
+
+  return Swimlanes.find(
+    {
+      archived: false,
+      _id: { $in: swimlanes },
+    },
+    {
+      fields: {
+        _id: 1,
+        title: 1,
+        type: 1,
+        sort: 1,
+      },
+      // sort: {
+      //   sort: ['boardId', 'listId', 'sort'],
+      // },
+    },
+  );
+});
+
+Meteor.publish('myLists', function() {
+  const userId = this.userId;
+  const lists = [];
+
+  Cards.find({
+    archived: false,
+    $or: [{ members: userId }, { assignees: userId }],
+  }).forEach(card => {
+    lists.push(card.listId);
+  });
+
+  return Lists.find(
+    {
+      archived: false,
+      _id: { $in: lists },
+    },
+    {
+      fields: {
+        _id: 1,
+        title: 1,
+        type: 1,
+        sort: 1,
+      },
+      // sort: {
+      //   sort: ['boardId', 'listId', 'sort'],
+      // },
+    },
+  );
+});
+
 Meteor.publish('archivedBoards', function() {
 Meteor.publish('archivedBoards', function() {
   const userId = this.userId;
   const userId = this.userId;
   if (!Match.test(userId, String)) return [];
   if (!Match.test(userId, String)) return [];

+ 27 - 0
server/publications/cards.js

@@ -2,3 +2,30 @@ Meteor.publish('card', cardId => {
   check(cardId, String);
   check(cardId, String);
   return Cards.find({ _id: cardId });
   return Cards.find({ _id: cardId });
 });
 });
+
+Meteor.publish('myCards', function() {
+  const userId = this.userId;
+
+  return Cards.find(
+    {
+      archived: false,
+      $or: [{ members: userId }, { assignees: userId }],
+    },
+    {
+      fields: {
+        _id: 1,
+        boardId: 1,
+        swimlaneId: 1,
+        listId: 1,
+        title: 1,
+        type: 1,
+        sort: 1,
+        members: 1,
+        assignees: 1,
+      },
+      // sort: {
+      //   sort: ['boardId', 'listId', 'sort'],
+      // },
+    },
+  );
+});