Collection Items Implemented
This commit is contained in:
1 parent
b48450eb66
commit
54b300f979
3 files changed
+201
-40
No files matched your search
@@ -19,23 +19,23 @@ function newStrategySpace () {
|
||||
return thisObject
|
||||
|
||||
async function initialize () {
|
||||
thisObject.strategyCollection = newStrategyCollection()
|
||||
await thisObject.strategyCollection.initialize()
|
||||
|
||||
thisObject.sidePanel = newSidePanel()
|
||||
thisObject.sidePanel.initialize()
|
||||
|
||||
thisObject.strategyCollection = newStrategyCollection()
|
||||
thisObject.strategyCollection.container.connectToParent(thisObject.sidePanel.container, true, true)
|
||||
await thisObject.strategyCollection.initialize()
|
||||
|
||||
thisObject.sidePanel.areas.push(thisObject.strategyCollection)
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
container = thisObject.strategyCollection.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
|
||||
container = thisObject.sidePanel.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
|
||||
if (thisObject.sidePanel !== undefined) {
|
||||
container = thisObject.sidePanel.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -6,32 +6,34 @@ function newStrategyCollection () {
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
let thisObject = {
|
||||
collection: undefined,
|
||||
strategies: undefined,
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
let colletionItems = []
|
||||
|
||||
thisObject.container.frame.width = viewPort.visibleArea.topRight.x - viewPort.visibleArea.topLeft.x
|
||||
thisObject.container.frame.height = viewPort.visibleArea.topLeft.y - viewPort.visibleArea.bottomLeft.y
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.name = MODULE_NAME
|
||||
thisObject.container.initialize()
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.topLeft.x
|
||||
container.frame.position.y = viewPort.visibleArea.topLeft.y
|
||||
thisObject.container.frame.width = 0
|
||||
thisObject.container.frame.height = 0
|
||||
|
||||
container.isDraggeable = false
|
||||
container.isClickeable = true
|
||||
thisObject.container.frame.position.x = 0
|
||||
thisObject.container.frame.position.y = 0
|
||||
|
||||
thisObject.container.isDraggeable = false
|
||||
thisObject.container.isClickeable = true
|
||||
|
||||
return thisObject
|
||||
|
||||
async function initialize () {
|
||||
try {
|
||||
const accessToken = window.localStorage.getItem('access_token')
|
||||
let user = window.localStorage.getItem('user')
|
||||
const accessToken = window.localStorage.getItem('xaccess_token')
|
||||
let user = window.localStorage.getItem('xuser')
|
||||
|
||||
if (user === null) {
|
||||
// if there is no user that means that we are logged off, which means this object can not be used.
|
||||
@@ -179,7 +181,8 @@ function newStrategyCollection () {
|
||||
})
|
||||
.then(response => {
|
||||
window.localStorage.setItem('userStrategies', JSON.stringify(response.data.strategizer_StrategyByFb.subStrategies))
|
||||
thisObject.collection = response.data.strategizer_StrategyByFb.subStrategies
|
||||
thisObject.strategies = response.data.strategizer_StrategyByFb.subStrategies
|
||||
createCollectionItems()
|
||||
resolve({ strategies: response.data.strategizer_StrategyByFb.subStrategies})
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -205,6 +208,23 @@ function newStrategyCollection () {
|
||||
}
|
||||
}
|
||||
|
||||
function createCollectionItems () {
|
||||
const TOP_MARGIN = 100
|
||||
const ITEMS_SEPARATION = 70
|
||||
|
||||
for (let i = 0; i < thisObject.strategies.length; i++) {
|
||||
let strategy = thisObject.strategies[i]
|
||||
let collectionItem = newStrategyCollectionItem()
|
||||
|
||||
collectionItem.container.connectToParent(thisObject.container, false, false)
|
||||
collectionItem.initialize()
|
||||
collectionItem.strategy = strategy
|
||||
collectionItem.container.frame.position.y = i * ITEMS_SEPARATION + TOP_MARGIN
|
||||
|
||||
colletionItems.push(collectionItem)
|
||||
}
|
||||
}
|
||||
|
||||
function onClick () {
|
||||
|
||||
}
|
||||
@@ -224,27 +244,13 @@ function newStrategyCollection () {
|
||||
}
|
||||
|
||||
function draw () {
|
||||
if (thisObject.collection === undefined) {
|
||||
if (colletionItems === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
const ROW_HEIGHT = 50
|
||||
const LEFT_MARGIN = 50
|
||||
const TOP_MARGIN = 10
|
||||
|
||||
for (let i = 0; i < thisObject.collection.length; i++) {
|
||||
let strategy = thisObject.collection[i]
|
||||
|
||||
let labelPoint = {
|
||||
x: LEFT_MARGIN,
|
||||
y: TOP_MARGIN + i * ROW_HEIGHT
|
||||
}
|
||||
|
||||
let labelToPrint = strategy.name
|
||||
let opacity = 1
|
||||
let fontSize = 12
|
||||
|
||||
printLabel(labelToPrint, labelPoint.x, labelPoint.y, opacity, fontSize)
|
||||
for (let i = 0; i < colletionItems.length; i++) {
|
||||
let item = colletionItems[i]
|
||||
item.draw()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
function newStrategyCollectionItem () {
|
||||
const MODULE_NAME = 'Strategy Collection Item'
|
||||
let thisObject = {
|
||||
strategy: undefined,
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let isInitialized = false
|
||||
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.name = MODULE_NAME
|
||||
thisObject.container.initialize()
|
||||
thisObject.container.isClickeable = true
|
||||
thisObject.container.isDraggeable = false
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize () {
|
||||
const ITEM_WIDTH = 400
|
||||
const ITEM_HEIGHT = 60
|
||||
|
||||
thisObject.container.frame.width = ITEM_WIDTH
|
||||
thisObject.container.frame.height = ITEM_HEIGHT
|
||||
|
||||
const LEFT_MARGIN = (thisObject.container.parentContainer.frame.width - thisObject.container.frame.width) / 2
|
||||
const TOP_MARGIN = 100
|
||||
|
||||
thisObject.container.frame.position.x = LEFT_MARGIN
|
||||
thisObject.container.frame.position.y = TOP_MARGIN
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick)
|
||||
isInitialized = true
|
||||
}
|
||||
|
||||
function onMouseClick (event) {
|
||||
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
let container
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
return thisObject.container
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function draw () {
|
||||
if (isInitialized === false) { return }
|
||||
|
||||
borders()
|
||||
text()
|
||||
}
|
||||
|
||||
function text () {
|
||||
if (thisObject.strategy === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
const LEFT_MARGIN = 50
|
||||
const TOP_MARGIN = 30
|
||||
|
||||
let strategy = thisObject.strategy
|
||||
|
||||
let labelPoint = {
|
||||
x: LEFT_MARGIN,
|
||||
y: TOP_MARGIN
|
||||
}
|
||||
|
||||
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
|
||||
|
||||
let labelToPrint = strategy.name
|
||||
labelToPrint = labelToPrint.toUpperCase()
|
||||
labelToPrint = labelToPrint.substring(0, 30)
|
||||
let opacity = 1
|
||||
let fontSize = 15
|
||||
|
||||
printLabel(labelToPrint, labelPoint.x, labelPoint.y, opacity, fontSize)
|
||||
}
|
||||
|
||||
function borders () {
|
||||
let point1
|
||||
let point2
|
||||
let point3
|
||||
let point4
|
||||
|
||||
point1 = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
point2 = {
|
||||
x: thisObject.container.frame.width,
|
||||
y: 0
|
||||
}
|
||||
|
||||
point3 = {
|
||||
x: thisObject.container.frame.width,
|
||||
y: thisObject.container.frame.height
|
||||
}
|
||||
|
||||
point4 = {
|
||||
x: 0,
|
||||
y: thisObject.container.frame.height
|
||||
}
|
||||
|
||||
point1 = thisObject.container.frame.frameThisPoint(point1)
|
||||
point2 = thisObject.container.frame.frameThisPoint(point2)
|
||||
point3 = thisObject.container.frame.frameThisPoint(point3)
|
||||
point4 = thisObject.container.frame.frameThisPoint(point4)
|
||||
|
||||
let opacity
|
||||
|
||||
/* Shadow */
|
||||
|
||||
for (let i = 0; i <= 5; i++) {
|
||||
opacity = 1 - (i / 100) - 0.93
|
||||
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.moveTo(point1.x + i, point1.y + i)
|
||||
browserCanvasContext.lineTo(point2.x + i, point2.y + i)
|
||||
browserCanvasContext.lineTo(point3.x + i, point3.y + i)
|
||||
browserCanvasContext.lineTo(point4.x + i, point4.y + i)
|
||||
browserCanvasContext.lineTo(point1.x + i, point1.y + i)
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.BLACK + ', ' + opacity + ''
|
||||
browserCanvasContext.lineWidth = 1
|
||||
browserCanvasContext.stroke()
|
||||
}
|
||||
|
||||
/* Background and Border */
|
||||
|
||||
browserCanvasContext.setLineDash([0, 0])
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.moveTo(point1.x, point1.y)
|
||||
browserCanvasContext.lineTo(point2.x, point2.y)
|
||||
browserCanvasContext.lineTo(point3.x, point3.y)
|
||||
browserCanvasContext.lineTo(point4.x, point4.y)
|
||||
browserCanvasContext.lineTo(point1.x, point1.y)
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
opacity = 1
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + opacity + ''
|
||||
browserCanvasContext.fill()
|
||||
|
||||
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREY + ', ' + opacity + ''
|
||||
browserCanvasContext.lineWidth = 0.3
|
||||
browserCanvasContext.stroke()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user