Skip to content

Commit

Permalink
Dates
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyjor committed Oct 7, 2024
1 parent e6d71e9 commit 5b31865
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 41 deletions.
8 changes: 6 additions & 2 deletions src/api/nodes/NodeController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ const NodeController = {
ipcRenderer.sendSync('api:deleteNode', nodeId, parentId);
},

updateNodeProperty(propertyToUpdate, nodeId, newValue) {
const trelloAuth = {
updateNodeProperty(propertyToUpdate, nodeId, newValue, shouldSync = true) {
let trelloAuth = {
key: localStorage.getItem(`trelloKey`),
token: localStorage.getItem(`trelloToken`),
};

if (!shouldSync) {
trelloAuth = null;
}

return ipcRenderer.sendSync(
'api:updateNodeProperty',
propertyToUpdate,
Expand Down
47 changes: 31 additions & 16 deletions src/components/NodeModal/NodeModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function NodeModal({
iterations,
node,
parents,
syncTrelloCard,
updateNodeProperty,
visible,
}) {
Expand Down Expand Up @@ -53,6 +54,9 @@ function NodeModal({
[node?.id, updateNodeProperty],
);

const trelloToken = localStorage.getItem('trelloToken');
const trelloKey = localStorage.getItem(`trelloKey`);

return node ? (
<Modal
title={
Expand Down Expand Up @@ -137,22 +141,33 @@ function NodeModal({
updateNodeProperty('notes', node.id, value, true);
}}
/>
<div>Iteration</div>
<Select
style={{ width: 200 }}
value={node.iterationId}
onChange={onChangeIteration}
>
<Option style={{ width: '100%' }} key={0} value={0}>
<span style={{ whiteSpace: 'normal' }}>Backlog</span>
</Option>
{iterations &&
Object.values(iterations).map((item) => (
<Option style={{ width: '100%' }} key={item.id} value={item.id}>
<span style={{ whiteSpace: 'normal' }}>{item.title}</span>
</Option>
))}
</Select>
<div>
<div>Iteration</div>
<Select
style={{ width: 200 }}
value={node.iterationId}
onChange={onChangeIteration}
>
<Option style={{ width: '100%' }} key={0} value={0}>
<span style={{ whiteSpace: 'normal' }}>Backlog</span>
</Option>
{iterations &&
Object.values(iterations).map((item) => (
<Option
style={{ width: '100%' }}
key={item.id}
value={item.id}
>
<span style={{ whiteSpace: 'normal' }}>{item.title}</span>
</Option>
))}
</Select>
{trelloKey && trelloToken && node.trello && (
<Button style={{ marginLeft: `150px` }} onClick={syncTrelloCard}>
Trello Sync
</Button>
)}
</div>
</TabPane>
<TabPane
style={{ margin: '0 10px 0 0' }}
Expand Down
38 changes: 33 additions & 5 deletions src/pages/ProjectPage/ProjectPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,40 @@ class ProjectPage extends Component {
});
};

syncTrelloCard = (node) => {
console.log('syncing');
fetch(
`https://api.trello.com/1/cards/${node.trello.id}?key=${this.trelloKey}&token=${this.trelloToken}`,
{
method: 'GET',
headers: {
Accept: 'application/json',
},
},
)
.then((response) => {
console.log(`Response: ${response.status} ${response.statusText}`);
return response.text();
})
.then((text) => {
const card = JSON.parse(text);
const local = new Date(node.lastUpdated);
const remote = new Date(card.dateLastActivity);

if (local > remote) {
console.log('need to update remote');
} else if (remote.getTime() - local.getTime() >= 10000) {
console.log('need to update local');
} else {
console.log('nothing to sync here...');
}
})
.catch((err) => console.error(err));
};

// eslint-disable-next-line class-methods-use-this
updateNodeProperty = (propertyToUpdate, nodeId, newValue) => {
NodeController.updateNodeProperty(
propertyToUpdate,
nodeId,
newValue,
);
NodeController.updateNodeProperty(propertyToUpdate, nodeId, newValue);

const newState = {
...this.state,
Expand Down Expand Up @@ -460,6 +487,7 @@ class ProjectPage extends Component {
iterations={iterations}
node={nodes[modalNodeId]}
parents={parents}
syncTrelloCard={this.syncTrelloCard}
updateNodeProperty={this.updateNodeProperty}
visible={nodeModalVisible}
/>
Expand Down
16 changes: 2 additions & 14 deletions src/services/ISO8601Service.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
const ISO8601Service = {
getISO8601Time() {
const today = new Date();
const month = today.getMonth() + 1;
const day = today.getDate();

const date = `${today.getFullYear()}-${month < 10 ? `0${month}` : month}-${
day < 10 ? `0${day}` : day
}`;
const hours = today.getHours();
const minutes = today.getMinutes();
const seconds = today.getSeconds();
const time = `${hours < 10 ? `0${hours}` : hours}:${
minutes < 10 ? `0${minutes}` : minutes
}:${seconds < 10 ? `0${seconds}` : seconds}`;
return `${date}T${time}`;
const now = new Date();
return now.toISOString();
},
};

Expand Down
15 changes: 11 additions & 4 deletions src/services/NodeService.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ const NodeService = {
};

const parent = lokiService.parents.findOne({ id: { $eq: parentId } });
console.log(`parents:`);
console.log(parent);
if (trelloData) {
nodeData.trello = trelloData;
nodeData.description = trelloData.desc;
Expand Down Expand Up @@ -205,6 +203,7 @@ const NodeService = {
.find({ id: nodeId })
.update((node) => {
node[propertyToUpdate] = newValue;
node.lastUpdated = `${ISO8601ServiceInstance.getISO8601Time()}`;
nodeToReturn = node;
});

Expand All @@ -216,7 +215,6 @@ const NodeService = {
);
}

console.log(trelloAuth);
if (nodeToReturn.trello && trelloAuth) {
const url = `https://api.trello.com/1/cards/${nodeToReturn.trello.id}?key=${trelloAuth.key}&token=${trelloAuth.token}&name=${nodeToReturn.title}&desc=${nodeToReturn.description}`;

Expand All @@ -235,7 +233,16 @@ const NodeService = {
return response.data;
})
.then((data) => {
console.log(data);
lokiService.nodes
.chain()
.find({ id: nodeId })
.update((node) => {
node.trello = data;
nodeToReturn = node;
});

lokiService.saveDB();
console.log(`Node's trello data saved successfully.`);
})
.catch((err) => {
console.error(err);
Expand Down

0 comments on commit 5b31865

Please sign in to comment.