diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..d6e74d64 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/backend/app.js" + } + ] +} \ No newline at end of file diff --git a/backend/app.js b/backend/app.js index 76439f06..4935d25a 100644 --- a/backend/app.js +++ b/backend/app.js @@ -88,7 +88,7 @@ function storeToken(token) { try { fs.mkdirSync(TOKEN_DIR); } catch (err) { - if (err.code != 'EEXIST') { + if (err.code !== 'EEXIST') { throw err; } } @@ -109,11 +109,15 @@ function getPairs(callback){ if(err) { // Handle error console.log(err); - return null; + callback(null, true); } else { const pairs = []; - lastRow = result.valueRanges[0].values.length; + try{ + lastRow = result.valueRanges[0].values.length; + }catch(err){ + lastRow = 0; + } for (let i=0;i{ - if ((pair.name1==names[i] && pair.name2==names[j])||(pair.name1==names[j] && pair.name2==names[i])){ - found=true; - return; - } - }); + let matrix_row = []; + for (let j=0;j<=i;j++) (i===j)? matrix_row.push(1):matrix_row.push(0); + matrix.push(matrix_row); + } - if (!found){ - usedNames.filter((name)=>{ - if (names[i] === name || names[j] === name){ - found=true; - return; - } - }); - } - + //Mark existing pairs, put 3 in matrix fields + pairs.filter((pair)=>{ - if (!found){ - next_i=true; - newPairs.push({name1:names[i], name2:names[j]}); - usedNames.push(names[i]); - usedNames.push(names[j]); - break; - } + let name1_id = names.indexOf(pair.name1); + let name2_id = names.indexOf(pair.name2); + + if (name1_id !== -1 && name2_id !== -1){ + if (name1_id > name2_id){ + matrix[name1_id][name2_id] = 3; + }else{ + matrix[name2_id][name1_id] = 3; } } - if (next_i) continue; + }); + + tree = []; + done=false; + + for (let i=0;i tree[max_count_index].length) + max_count_index = i; + } + + let result_pairs = []; + if (tree.length > 0){ + for (let i=0;i{ + if (a>b) return -1; else return 1; + }); + + for (let i=0;i Provjeri da li postoji -> Snimi ili ponovi postupak - + } function SavePairs(callback){ - if (lastRow== null) return; + if (lastRow=== null) { + callback.send({result:true}); + return; + } auth=oauth2Client; @@ -220,6 +321,7 @@ function SavePairs(callback){ const data = []; + if (lastRow === 0) lastRow=-1; let range1= '2017!A'+(lastRow+2)+':A'+(lastRow+2+pairsForSave.length); let range2= '2017!B'+(lastRow+2)+':B'+(lastRow+2+pairsForSave.length); @@ -269,15 +371,13 @@ app.use(function(req, res, next) { app.get('/getPairs',(req,resp)=>{ pairsForSave=[]; lastRow=null; - MakePairs(resp); + MakePairsV3(resp); }); app.get('/savePairs', (req,resp)=>{ SavePairs(resp); - //resp.send({result:true}); }); - app.listen(3005, function () { - console.log('server na portu 3005'); + console.log("Server running - Port 3005"); }) \ No newline at end of file diff --git a/web/src/App.js b/web/src/App.js index e54465ad..6e8163fa 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -18,10 +18,10 @@ class App extends Component { getPairsEventHandler = (event) =>{ let url = `http://${BASE_URL}:3005/getPairs`; - this.setState({waitingPairs:true}); + this.setState({waitingPairs:true, renderFinish:false, waitingSave:true}); fetch(url, {}).then(function(response) { return response.json(); }).then(function(data) { - this.setState({pairs : data, renderPairsList:true, waitingPairs:false}); + this.setState({pairs : data.pairs, left:data.left, renderPairsList:!data.error, waitingPairs:false, waitingSave:false, error: data.error, error_message: data.error_message}); }.bind(this)); @@ -46,13 +46,32 @@ class App extends Component {
-
-

List of pairs :

-
+ { + this.state.error && +
+

Error - {this.state.error_message}

+
+ } + { + this.state.renderPairsList && +
+

List of pairs :

+
+ } { this.state.renderPairsList && } + { + this.state.renderPairsList && this.state.left && +
+

Without pair :

+ { + this.state.left.map((name, index) => + (
{index+1}. {name}
)) + } +
+ } { this.state.renderPairsList && diff --git a/web/src/PairComponent.js b/web/src/PairComponent.js index e6dd674d..7987ff92 100644 --- a/web/src/PairComponent.js +++ b/web/src/PairComponent.js @@ -3,14 +3,14 @@ import React, { Component } from 'react'; export default class PairComponent extends Component{ constructor(props) { super(props); - this.state = {pairName: this.props.pair}; + this.state = {pairName: this.props.pair, index: this.props.index}; } render(){ return (
-
{this.state.pairName.name1} - {this.state.pairName.name2}
+
{this.state.index+1}. {this.state.pairName.name1} - {this.state.pairName.name2}
) diff --git a/web/src/PairsListComponent.js b/web/src/PairsListComponent.js index 9002b638..18032d0f 100644 --- a/web/src/PairsListComponent.js +++ b/web/src/PairsListComponent.js @@ -7,7 +7,7 @@ export default class PairsListComponent extends Component{
{ this.props.pairs.map((pair, index) => - ()) + ()) }
)