Skip to content

Commit

Permalink
fixed merge conflicts with card.js, canvas-test.js, and card-test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
laurengastineau committed Aug 8, 2017
2 parents 374127f + 5a65df1 commit 93bd66a
Show file tree
Hide file tree
Showing 12 changed files with 487 additions and 92 deletions.
32 changes: 29 additions & 3 deletions app/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,36 @@ const Card = require('../app/Card.js');
module.exports = class Canvas {
constructor() {
this.cards = [];

this.canvas = document.createElement('div');
$(this.canvas).attr('class', 'canvas');

const versionDialogButton = document.createElement('button');
$(versionDialogButton).click(() => { this.displayVersion(); });
$(versionDialogButton).html('Version');

const modalDialogButton = document.createElement('button');
$(modalDialogButton).click(() => { this.addObj(); });
$(modalDialogButton).html('Modal Dialog');

const addCardButton = document.createElement('button');
$(addCardButton).click(() => { this.addCard('text'); });
$(addCardButton).html('Add Card');

const printCardsButton = document.createElement('button');
$(printCardsButton).click(() => { this.printCards(); });
$(printCardsButton).html("Print Card(s)");

this.canvas.appendChild(versionDialogButton);
this.canvas.appendChild(modalDialogButton);
this.canvas.appendChild(document.createElement('br'));
this.canvas.appendChild(addCardButton);
this.canvas.appendChild(printCardsButton);
document.body.appendChild(this.canvas);
}

addCard(cardType = 'text') {
let card = new Card(this.nextCardId());
addCard(cardType = 'text', modality = true) {
let card = new Card({id: this.nextCardId(), context: this.canvas, modal: modality});
this.cards.push(card);
}

Expand All @@ -28,7 +54,7 @@ module.exports = class Canvas {
}

printCards() {
console.log('CARDS: (' + this.cards.length + ')');
console.log('CARDS (' + this.cards.length + ')');
for (var card of this.cards) {
console.log('card: ' + card.id);
}
Expand Down
63 changes: 56 additions & 7 deletions app/Card.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
"use strict";
const Error = require('../app/Error.js');

module.exports = class Card {
constructor(id = throwIfMissing('id'), type, fileData) {
this.id = id; //establishes id of each card
this.name = ""; //updated in cardbuilder
this.inStack = false; //false if card is not in a stack

constructor({
id = Error.throwIfMissing('id'),
context = Error.throwIfMissing('context'),
modal = true
}) {
this.id = id;
this.createdBy = require('username').sync();
this.createdTimestamp = new Date();
this.lastInteraction = new Date();

this.card = document.createElement('div');
$(this.card).attr({
id: this.id,
class: 'card',
});

this.header = document.createElement('div');
$(this.header).attr('class', 'card-header');

this.title = document.createElement('span');
$(this.title).html("My Card");

this.header.appendChild(this.title);
this.card.appendChild(this.header);
context.appendChild(this.card);
if (modal) this.toggleDraggable();
}


//for metadata
this.createdTimestamp = new Date().toString();
Expand Down Expand Up @@ -91,8 +117,31 @@ module.exports = class Card {
$(id).html(updatedMetadata);
return updatedMetadata;
}
}

function throwIfMissing(param) {
throw new Error('Missing parameter \'' + param + '\'');
toggleDraggable() {
// warning: draggable object must be appended to DOM before being enabled
if ($(this.card).data('draggable')) {
$(this.card).draggable('disable');
} else {
$(this.card).draggable({
handle: '.card-header',
containment: 'window',
start: function() {
$(this).css({
transform: 'none',
top: $(this).offset().top+'px',
left: $(this).offset().left+'px'
});
}
});
}
}

toggleDroppable() {
if ($(this.card).data('droppable')) {
$(this.card).droppable('disable');
} else {
$(this.card).droppable();
}
}
}
7 changes: 7 additions & 0 deletions app/Error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {

throwIfMissing: function(param) {
throw new Error('Missing parameter \'' + param + '\'');
}

}
9 changes: 2 additions & 7 deletions lib/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@
menu.popup(remote.getCurrentWindow())
}, false)
</script> -->
</head>
<body>
<script>
var Canvas = require('../app/Canvas.js');
var canvas = new Canvas();
</script>
</head>
<body>
<button onclick="canvas.displayVersion()" class="version">Version</button>
<button onclick="canvas.addObj()" class="test">addObj</button>
<br />
<button onclick="canvas.addCard('text')" class="test">addCard</button>
<button onclick="canvas.printCards()" class="test">printCards</button>
</body>
</html>
Loading

0 comments on commit 93bd66a

Please sign in to comment.