diff --git a/src/routes/index.svelte b/src/routes/index.svelte index f655150..6b88f57 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -8,17 +8,20 @@ window.location.href = url; } + let id; + function connect() { - + const url=`http://localhost:3000/room/?id=${id}`; + window.location.href = url; } - Varian.cc + Варианты -

varian.cc

+

Варианты

Создать работу

@@ -47,7 +50,7 @@
Код подключения:
- +
diff --git a/src/routes/room.svelte b/src/routes/room.svelte index 8e9ffb8..cf9cbf4 100644 --- a/src/routes/room.svelte +++ b/src/routes/room.svelte @@ -17,32 +17,98 @@ room = await res.json(); console.log(room); }); + + String.prototype.toColor = function() { + var colors = ['#FF6633', '#FFB399', '#FF33FF', '#FFFF99', '#00B3E6', + '#E6B333', '#3366E6', '#999966', '#99FF99', '#B34D4D', + '#80B300', '#809900', '#E6B3B3', '#6680B3', '#66991A', + '#FF99E6', '#CCFF1A', '#FF1A66', '#E6331A', '#33FFCC', + '#66994D', '#B366CC', '#4D8000', '#B33300', '#CC80CC', + '#66664D', '#991AFF', '#E666FF', '#4DB3FF', '#1AB399', + '#E666B3', '#33991A', '#CC9999', '#B3B31A', '#00E680', + '#4D8066', '#809980', '#E6FF80', '#1AFF33', '#999933', + '#FF3380', '#CCCC00', '#66E64D', '#4D80CC', '#9900B3', + '#E64D66', '#4DB380', '#FF4D4D', '#99E6E6', '#6666FF']; + + var hash = 0; + if (this.length === 0) return hash; + for (var i = 0; i < this.length; i++) { + hash = this.charCodeAt(i) + ((hash << 5) - hash); + hash = hash & hash; + } + hash = ((hash % colors.length) + colors.length) % colors.length; + return colors[hash]; + } + + let nameInput = []; + let enabledInput; function selectVar(selected) { if (!room.teams[selected]) { room.teams[selected] = []; } - room.teams[selected][room.teams[selected].length] = "Толя"; - console.log(room.teams[selected]); + if (nameInput[selected] !== "" && nameInput[selected] !== undefined) { + room.teams[selected][room.teams[selected].length] = nameInput[selected]; + //room.teams[selected].push(nameInput[selected]); + var url = `http://localhost:3000/api/select/?id=${parsed.id}&name=${nameInput[selected]}&team=${selected}`; + fetch(url); + nameInput[selected] = ""; + } + } + + function selectInput(selected) { + enabledInput = selected; + } + + let highlightedTeam, highlightedName; + function highlightName(name, i) { + if (i === highlightedTeam && name === highlightedName) { + highlightedTeam = undefined; + highlightedName = undefined; + } else { + highlightedTeam = i; + highlightedName = name; + } + } + + function removeName() { + const index = room.teams[highlightedTeam].indexOf(highlightedName); + if (index > -1) { + room.teams[highlightedTeam].splice(index, 1); + } + var url = `http://localhost:3000/api/delete/?id=${parsed.id}&name=${highlightedName}&team=${highlightedTeam}`; + fetch(url); } - + Варианты {#if room}

{room.name}

+

По {room.group ? "бригадам" : "вариантам"}

    {#each room.teams as _, i} -
  1. selectVar(i)}> +
  2. selectInput(i)} style="border-color: {enabledInput==i ? 'gray' : 'lightgray'}"> {#each room.teams[i] as name} - {name} + highlightName(name, i)}> + {name} + {#if (i === highlightedTeam && name === highlightedName)} + × + {/if} + {/each} + {#if room.teams[i].length == 0 || room.group == "true"} + selectVar(i)}> + + {/if}
  3. {/each}
+ + {:else} Loading... {/if} @@ -51,6 +117,12 @@ \ No newline at end of file diff --git a/src/server.js b/src/server.js index 0cf3739..88ae551 100644 --- a/src/server.js +++ b/src/server.js @@ -31,6 +31,7 @@ MongoClient.connect(process.env.DB_CONNECTION, { useUnifiedTopology: true }) next(); }); + // n, g, c app.get('/api/create/', (req, res) => { console.log(req.query); const id = uuidv4(); @@ -46,9 +47,10 @@ MongoClient.connect(process.env.DB_CONNECTION, { useUnifiedTopology: true }) "teams": teams }); - res.redirect(`http://localhost:3000/room/?id=${id}`); + res.redirect(`${process.env.URL}:3000/room/?id=${id}`); }); + // id app.get('/api/join/', (req, res) => { rooms.findOne({ "id": req.query.id }).then(room => { res.writeHead(200, { 'Content-Type': 'application/json' }); @@ -57,6 +59,25 @@ MongoClient.connect(process.env.DB_CONNECTION, { useUnifiedTopology: true }) }); }); + // id, team, name + app.get('/api/select/', (req, res) => { + rooms.findOne({ "id": req.query.id }).then(room => { + room.teams[req.query.team].push(req.query.name); + rooms.findOneAndReplace({ "id": req.query.id }, room).then(() => res.end()); + }); + }); + + // id, team, name + app.get('/api/delete/', (req, res) => { + rooms.findOne({ "id": req.query.id }).then(room => { + const index = room.teams[req.query.team].indexOf(req.query.name); + if (index > -1) { + room.teams[req.query.team].splice(index, 1); + } + rooms.findOneAndReplace({ "id": req.query.id }, room).then(() => res.end()); + }); + }); + app.use( compression({ threshold: 0 }), sirv('static', { dev }), diff --git a/src/template.html b/src/template.html index 7c0f817..fea86cc 100644 --- a/src/template.html +++ b/src/template.html @@ -9,7 +9,7 @@ - +