List implemented

This commit is contained in:
Sebastian Seedorf
2019-01-11 16:57:22 +01:00
parent 62985d2e2a
commit fc582eb48c
11 changed files with 241 additions and 156 deletions

View File

@@ -1,29 +1,5 @@
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<DBN-PSQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false" />
</DBN-PSQL>
<DBN-SQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false">
<option name="STATEMENT_SPACING" value="one_line" />
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</DBN-SQL>
<DBN-PSQL> <DBN-PSQL>
<case-options enabled="false"> <case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" /> <option name="KEYWORD_CASE" value="lower" />

5
app.js
View File

@@ -7,11 +7,11 @@ var low = require("lowdb");
var FileSync = require("lowdb/adapters/FileSync"); var FileSync = require("lowdb/adapters/FileSync");
var logger = require("morgan"); var logger = require("morgan");
var path = require("path"); var path = require("path");
var read = require("read-file");
var uuidv4 = require("uuid/v4"); var uuidv4 = require("uuid/v4");
var indexRouter = require("./routes/index"); var indexRouter = require("./routes/index");
var updateRouter = require("./routes/update"); var updateRouter = require("./routes/update");
var usersRouter = require("./routes/users"); var usersRouter = require("./routes/users");
var read = require("read-file");
var app = express(); var app = express();
var adapter = new FileSync("db.json"); var adapter = new FileSync("db.json");
var db = low(adapter); var db = low(adapter);
@@ -21,6 +21,7 @@ db.defaults({ users: [] })
app.cocktails = []; app.cocktails = [];
read("data/output.csv", "utf8", function (err, buffer) { read("data/output.csv", "utf8", function (err, buffer) {
// console.log(buffer); // console.log(buffer);
var cocktailList = [];
var result = buffer.split(/\n|\r|\n\r|\r\n/); var result = buffer.split(/\n|\r|\n\r|\r\n/);
result = result.map(function (line) { result = result.map(function (line) {
line = line.split("\t"); line = line.split("\t");
@@ -31,10 +32,12 @@ read("data/output.csv", "utf8", function (err, buffer) {
line[1] = parseFloat(line[1]); line[1] = parseFloat(line[1]);
line[4] = line[4].substr(0, line[4].length - 2) + "," + line[4].substr(-2) + " \u20AC"; line[4] = line[4].substr(0, line[4].length - 2) + "," + line[4].substr(-2) + " \u20AC";
line[5] = line[5].substr(0, line[5].length - 2) + "," + line[5].substr(-2) + " \u20AC"; line[5] = line[5].substr(0, line[5].length - 2) + "," + line[5].substr(-2) + " \u20AC";
cocktailList.push(line[3]);
return line; return line;
}); });
result = result.filter(function (f) { return !!f; }); result = result.filter(function (f) { return !!f; });
app.cocktails = result; app.cocktails = result;
app.cocktailList = cocktailList;
}); });
// view engine setup // view engine setup
app.set("views", path.join(__dirname, "views")); app.set("views", path.join(__dirname, "views"));

View File

@@ -1 +1 @@
{"version":3,"file":"app.js","sourceRoot":"","sources":["app.ts"],"names":[],"mappings":";;AAAA,4CAA8C;AAC9C,iCAAmC;AACnC,yCAA2C;AAC3C,2BAA6B;AAC7B,kDAAoD;AACpD,+BAAiC;AACjC,2BAA6B;AAC7B,gCAAkC;AAElC,4CAA8C;AAC9C,8CAAgD;AAChD,4CAA8C;AAC9C,gCAAkC;AAElC,IAAM,GAAG,GAAG,OAAO,EAAE,CAAC;AACtB,IAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAA;AACvC,IAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC;AACxB,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC;AACZ,EA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AAE,CAAC;KACZ;IACD,IAAI,EAAE,CAAC;AACT,CAAC,CAAC,CAAC;AACH,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AAExD,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;AAC1B,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AAC/B,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AAEjC,yCAAyC;AACzC,GAAG,CAAC,GAAG,CAAC,UAAC,GAAG,EAAE,GAAG,EAAE,IAAI;IACrB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC;AAEH,gBAAgB;AAChB,GAAG,CAAC,GAAG,CAAC,UAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI;IAC1B,kDAAkD;IAClD,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IACjC,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAEnE,wBAAwB;IACxB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC;IAC9B,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACtB,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC"}

5
app.ts
View File

@@ -5,12 +5,12 @@ import * as low from "lowdb";
import * as FileSync from "lowdb/adapters/FileSync"; import * as FileSync from "lowdb/adapters/FileSync";
import * as logger from "morgan"; import * as logger from "morgan";
import * as path from "path"; import * as path from "path";
import * as read from "read-file";
import * as uuidv4 from "uuid/v4"; import * as uuidv4 from "uuid/v4";
import * as indexRouter from "./routes/index"; import * as indexRouter from "./routes/index";
import * as updateRouter from "./routes/update"; import * as updateRouter from "./routes/update";
import * as usersRouter from "./routes/users"; import * as usersRouter from "./routes/users";
import * as read from "read-file";
const app = express(); const app = express();
const adapter = new FileSync("db.json") const adapter = new FileSync("db.json")
@@ -26,6 +26,7 @@ app.cocktails = [];
read("data/output.csv", "utf8", (err, buffer) => { read("data/output.csv", "utf8", (err, buffer) => {
// console.log(buffer); // console.log(buffer);
const cocktailList = [];
let result = buffer.split(/\n|\r|\n\r|\r\n/); let result = buffer.split(/\n|\r|\n\r|\r\n/);
result = result.map((line) => { result = result.map((line) => {
line = line.split("\t"); line = line.split("\t");
@@ -36,10 +37,12 @@ read("data/output.csv", "utf8", (err, buffer) => {
line[1] = parseFloat(line[1]); line[1] = parseFloat(line[1]);
line[4] = `${line[4].substr(0, line[4].length - 2)},${line[4].substr(-2)}`; line[4] = `${line[4].substr(0, line[4].length - 2)},${line[4].substr(-2)}`;
line[5] = `${line[5].substr(0, line[5].length - 2)},${line[5].substr(-2)}`; line[5] = `${line[5].substr(0, line[5].length - 2)},${line[5].substr(-2)}`;
cocktailList.push(line[3]);
return line; return line;
}); });
result = result.filter((f) => !!f); result = result.filter((f) => !!f);
app.cocktails = result; app.cocktails = result;
app.cocktailList = cocktailList;
}); });

52
db.json
View File

@@ -6,6 +6,58 @@
"sex": "m", "sex": "m",
"cocktails": [], "cocktails": [],
"lastused": 1547169564875 "lastused": 1547169564875
},
{
"id": "fcd183e6-90cf-4f9c-b6d1-1546882d0b1b",
"age": 22,
"sex": "m",
"cocktails": [
{
"level": 6,
"cocktail": "Anne Süß"
},
{
"level": 5,
"cocktail": "Melly"
},
{
"level": 4,
"cocktail": "Kürbiskern"
},
{
"level": 7,
"cocktail": "Zungenkuss"
},
{
"level": 2,
"cocktail": "Hurricane"
},
{
"level": 4,
"cocktail": "Bellamie"
},
{
"level": 5,
"cocktail": "Singapur"
},
{
"level": 4,
"cocktail": "Lady Killer"
},
{
"level": 3,
"cocktail": "Scotty"
},
{
"level": 4,
"cocktail": "Sex on the Beach"
},
{
"level": 5,
"cocktail": "Kitzler"
}
],
"lastused": 1547221929512
} }
] ]
} }

View File

@@ -1,6 +1,14 @@
const HTTP_BASE = "http://localhost:3000";
function httpGetAsync(theUrl, callback) {
const HTTP_BASE = "http://127.0.0.1:3000";
const tokens = {};
function httpGetAsync(token: string, theUrl, callback = null) {
if (!!token && tokens[token]) {
clearTimeout(tokens[token]);
delete tokens[token];
}
const t = setTimeout(() => {
const xmlHttp = new XMLHttpRequest(); const xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = () => { xmlHttp.onreadystatechange = () => {
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
@@ -11,14 +19,78 @@ function httpGetAsync(theUrl, callback) {
}; };
xmlHttp.open("GET", theUrl, true); // true for asynchronous xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null); xmlHttp.send(null);
delete tokens[token];
}, 500);
if (!!token) {
tokens[token] = t;
}
}
function addProgressBarFunctionality(id: string) {
const rangediv = document.getElementById(id);
rangediv.getElementsByClassName("mdl-progress")[0].addEventListener("mdl-componentupgraded", () => {
let value = parseInt(rangediv.dataset.value, 10);
setProgress(rangediv, value);
rangediv.getElementsByClassName("mdl-list__item-secondary-info")[0].innerHTML = `${value}/7`;
rangediv.getElementsByClassName("minus-arrow")[0].addEventListener("click", () => {
value = Math.max(1, parseInt(rangediv.dataset.value, 10) - 1);
setProgress(rangediv, value);
if (!!rangediv.dataset.dosend) {
sendCocktail(id, value);
}
});
rangediv.getElementsByClassName("plus-arrow")[0].addEventListener("click", () => {
value = Math.min(7, parseInt(rangediv.dataset.value, 10) + 1);
setProgress(rangediv, value);
if (!!rangediv.dataset.dosend) {
sendCocktail(id, value);
}
});
});
}
function setProgress(rdiv, v) {
rdiv.dataset.value = v.toString();
rdiv.getElementsByClassName("mdl-progress")[0].MaterialProgress.setProgress(100 * (v - 1 ) / 6);
rdiv.getElementsByClassName("mdl-list__item-secondary-info")[0].innerHTML = `${v}/7`;
} }
function sendAge(elem) { function sendAge(elem) {
console.log(`age: ${elem.value}`); httpGetAsync("agetoken", `${HTTP_BASE}/update/personal?age=${encodeURI(elem.value)}`);
httpGetAsync(`${HTTP_BASE}/update/personal?age=${encodeURI(elem.value)}`, null);
} }
function sendSex(elem) { function sendSex(elem) {
console.log("gender: " + elem.value); httpGetAsync("sextoken", `${HTTP_BASE}/update/personal?sex=${encodeURI(elem.value)}`);
httpGetAsync(`${HTTP_BASE}/update/personal?sex=${encodeURI(elem.value)}`, null); }
function sendNewCocktail() {
const cocktail = document.getElementById("cocktails").value;
if (cocktail === "") {
return;
}
const level = document.getElementById("pnew").dataset.value;
httpGetAsync(null, `${HTTP_BASE}/update/newcocktail?cocktail=${encodeURI(cocktail)}&level=${encodeURI(level)}`);
const elem = document.getElementById(cocktail);
if (!!elem) {
setProgress(elem, level);
} else {
const list = document.getElementById("cocktaillist");
let NAME = cocktail;
let LEVEL = level;
list.innerHTML += (`<li class="mdl-list__item mdl-list__item--two-line"><span class="mdl-list__item-primary-content"><i class="material-icons mdl-list__item-avatar">local_bar</i><span>${NAME}</span><span class="mdl-list__item-sub-title"> </span></span><span class="mdl-list__item-secondary-content">
<div id="${NAME}" class="mdl-grid" style="width:100px;text-align:center;padding:0;margin:0" data-value=""+LEVEL+"">
<div class="mdl-cell" style="width:33.33333333%;margin-right:0px;margin-left:0px"><a class="minus-arrow mdl-list__item-secondary-action" href="#"><i class="material-icons">remove</i></a></div>
<div class="mdl-cell" style="width:33.33333333%;margin-right:0px;margin-left:0px">
<div class="mdl-progress mdl-js-progress" style="text-align:center"><span class="mdl-list__item-secondary-info"></span></div>
</div>
<div class="mdl-cell" style="width:33.33333333%;margin-right:0px;margin-left:0px"><a class="plus-arrow mdl-list__item-secondary-action" href="#"><i class="material-icons">add</i></a></div>
</div></span></li>`);
addProgressBarFunctionality(NAME);
}
}
function sendCocktail(id, value) {
const cocktail = id;
const level = value;
httpGetAsync("updatetoken" + id, `${HTTP_BASE}/update/newcocktail?cocktail=${encodeURI(cocktail)}&level=${encodeURI(level)}`);
} }

View File

@@ -13,7 +13,7 @@ router.use((req, res, next) => {
router.get("/", (req, res, next) => { router.get("/", (req, res, next) => {
const user = req.app.db.get("users").find({id: req.cookies.uid}).value(); const user = req.app.db.get("users").find({id: req.cookies.uid}).value();
console.log(user); console.log(user);
res.render("index", {title: "Liebingscocktails", user, cocktails: req.app.cocktails}); res.render("index", {title: "Liebingscocktails", user, cocktails: req.app.cocktails, cocktailList: req.app.cocktailList});
}); });
export = router; export = router;

View File

@@ -13,9 +13,9 @@ router.use((req, res, next) => {
}); });
router.get("/personal", (req, res) => { router.get("/personal", (req, res) => {
const ageStr = req.param("age", null); const ageStr = req.query.age || null;
const age = parseInt(ageStr, 10); const age = parseInt(ageStr, 10);
const sex = req.param("sex", null); const sex = req.query.sex || null;
const result: {age?: number, sex?: string} = {}; const result: {age?: number, sex?: string} = {};
if (age > 15 && age < 99) { if (age > 15 && age < 99) {
result.age = age; result.age = age;
@@ -36,4 +36,35 @@ router.get("/personal", (req, res) => {
res.send(); res.send();
}); });
router.get("/newcocktail", (req, res) => {
const db = (req.app as any).db;
const levelStr = req.query.level || null;
const level = parseInt(levelStr, 10);
const cocktail = req.query.cocktail || null;
const result: {level?: number, cocktail?: string} = {};
if (level > 0 && level < 8) {
result.level = level;
}
if (req.app.cocktailList.indexOf(cocktail) > -1) {
result.cocktail = cocktail;
}
if (!!result.level && !!result.cocktail) {
const findRes = db.get("users").find({id: req.cookies.uid}).get("cocktails").find({cocktail});
if (!findRes.value()) {
db.get("users")
.find({id: req.cookies.uid})
.get("cocktails")
.push(result)
.write();
} else {
findRes
.assign(result)
.write();
}
}
res.status(204);
res.send();
});
export = router; export = router;

View File

@@ -1,6 +1,13 @@
extends layout extends layout
block content block content
h1= message block content
.mdl-grid
.mdl-cell--3-offset-desktop
.mdl-cell.mdl-cell--6-col.mdl-cell--12-col-tablet
.demo-card-square.mdl-card.mdl-shadow--2dp
.mdl-card__title.mdl-card--expand
h2.mdl-card__title-text= message
.mdl-card__supporting-text
h2= error.status h2= error.status
pre #{error.stack} pre(style="font-size: 70%") #{error.stack}

View File

@@ -1,7 +1,7 @@
extends layout extends layout
mixin rangemaker(id) mixin rangemaker(id, start)
.mdl-grid(style="width:100px;text-align:center;padding:0;margin:0", id=id) .mdl-grid(style="width:100px;text-align:center;padding:0;margin:0", id=id, data-value=(start || "4"), data-dosend=(start !== undefined))
.mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px") .mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px")
a.minus-arrow.mdl-list__item-secondary-action(href='#') a.minus-arrow.mdl-list__item-secondary-action(href='#')
i.material-icons remove i.material-icons remove
@@ -12,36 +12,12 @@ mixin rangemaker(id)
a.plus-arrow.mdl-list__item-secondary-action(href='#') a.plus-arrow.mdl-list__item-secondary-action(href='#')
i.material-icons add i.material-icons add
script. script.
let m = null; addProgressBarFunctionality('#{id}')
let rangediv = document.getElementById('#{id}');
rangediv.getElementsByClassName('mdl-progress')[0].addEventListener('mdl-componentupgraded', function () {
m = this.MaterialProgress;
this.MaterialProgress.setProgress(100 * 3 / 7);
});
rangediv.getElementsByClassName('mdl-list__item-secondary-info')[0].innerHTML = "3/7";
rangediv.getElementsByClassName('minus-arrow')[0].addEventListener('click', function () {
m.setProgress(100);
});
block content block content
style. //script(src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.3/dist/tf.min.js", defer)
.demo-card-square.mdl-card { //script(src="/js/neuralnet.js", defer)
width: 100%;
}
.demo-card-square > .mdl-card__title {
color: #fff;
background: #795548;
}
.mdl-selectfield__select option {
font-family: "Helvetica", "Arial", sans-serif;
}
script(src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.3/dist/tf.min.js", defer)
script(src="/js/neuralnet.js", defer)
.mdl-grid .mdl-grid
.mdl-cell--3-offset-desktop .mdl-cell--3-offset-desktop
.mdl-cell.mdl-cell--6-col.mdl-cell--12-col-tablet .mdl-cell.mdl-cell--6-col.mdl-cell--12-col-tablet
@@ -50,7 +26,7 @@ block content
h2.mdl-card__title-text Über diese Seite h2.mdl-card__title-text Über diese Seite
.mdl-card__supporting-text .mdl-card__supporting-text
| Auf dieser Website kannst Du Deine Lieblingscocktails speichern und beim nächsten Mal wieder bestellen! | Auf dieser Website kannst Du Deine Lieblingscocktails speichern und beim nächsten Mal wieder bestellen!
h3 Freiwillige Informationen h4 Freiwillige Informationen
| Du kannst anonym Dein Alter und Geschlecht angeben, um die Cocktails weiter verbessern zu können. | Du kannst anonym Dein Alter und Geschlecht angeben, um die Cocktails weiter verbessern zu können.
.form .form
.mdl-selectfield.mdl-js-selectfield.mdl-selectfield--floating-label .mdl-selectfield.mdl-js-selectfield.mdl-selectfield--floating-label
@@ -76,82 +52,34 @@ block content
.mdl-card__title.mdl-card--expand .mdl-card__title.mdl-card--expand
h2.mdl-card__title-text Lieblingscocktails h2.mdl-card__title-text Lieblingscocktails
.mdl-card__supporting-text .mdl-card__supporting-text
ul.demo-list-two.mdl-list #cocktaillist.ul.demo-list-two.mdl-list
each cocktail in user.cocktails
- index = cocktailList.indexOf(cocktail.cocktail)
- cdetails = cocktails[index]
li.mdl-list__item.mdl-list__item--two-line li.mdl-list__item.mdl-list__item--two-line
span.mdl-list__item-primary-content span.mdl-list__item-primary-content
i.material-icons.mdl-list__item-avatar local_bar i.material-icons.mdl-list__item-avatar local_bar
span Bryan Cranston span= cocktail.cocktail
span.mdl-list__item-sub-title 62 Episodes, 62 Episodes, 62 Episodes, 62 Episodes, 62 Episodes, 62 Episodes, 62 Episodes span.mdl-list__item-sub-title= cdetails[7].replace(/;/g, ', ')
span.mdl-list__item-secondary-content span.mdl-list__item-secondary-content
.mdl-grid(style="width:100px;text-align:center;padding:0;margin:0") +rangemaker(cocktail.cocktail, cocktail.level)
.mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px")
a.mdl-list__item-secondary-action(href='#')
i.material-icons remove
.mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px")
#p1.mdl-progress.mdl-js-progress(style="text-align:center")
span.mdl-list__item-secondary-info 6/7
.mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px")
a.mdl-list__item-secondary-action(href='#')
i.material-icons add
script.
document.querySelector('#p1').addEventListener('mdl-componentupgraded', function () {
this.MaterialProgress.setProgress(100 * 6 / 7);
});
li.mdl-list__item.mdl-list__item--two-line
span.mdl-list__item-primary-content
i.material-icons.mdl-list__item-avatar local_bar
span Aaron Paul
span.mdl-list__item-sub-title 62 Episodes
span.mdl-list__item-secondary-content
.mdl-grid(style="width:100px;text-align:center;padding:0;margin:0")
.mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px")
a.mdl-list__item-secondary-action(href='#')
i.material-icons remove
.mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px")
#p2.mdl-progress.mdl-js-progress(style="text-align:center")
span.mdl-list__item-secondary-info 2/7
.mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px")
a.mdl-list__item-secondary-action(href='#')
i.material-icons add
script.
document.querySelector('#p2').addEventListener('mdl-componentupgraded', function () {
this.MaterialProgress.setProgress(100 * 2 / 7);
});
li.mdl-list__item.mdl-list__item--two-line
span.mdl-list__item-primary-content
i.material-icons.mdl-list__item-avatar local_bar
span Bob Odenkirk
span.mdl-list__item-sub-title 62 Episodes
span.mdl-list__item-secondary-content
.mdl-grid(style="width:100px;text-align:center;padding:0;margin:0")
.mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px")
a.mdl-list__item-secondary-action(href='#')
i.material-icons remove
.mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px")
#p3.mdl-progress.mdl-js-progress(style="text-align:center")
span.mdl-list__item-secondary-info 5/7
.mdl-cell(style="width:33.33333333%;margin-right:0px;margin-left:0px")
a.mdl-list__item-secondary-action(href='#')
i.material-icons add
script.
document.querySelector('#p3').addEventListener('mdl-componentupgraded', function () {
this.MaterialProgress.setProgress(100 * 5 / 7);
});
br br
.form br
br
#newcocktail.form
.mdl-grid .mdl-grid
.mdl-cell--6-col .mdl-cell--6-col
.mdl-selectfield.mdl-js-selectfield.mdl-selectfield--floating-label .mdl-selectfield.mdl-js-selectfield.mdl-selectfield--floating-label
select#gender.mdl-selectfield__select select#cocktails.mdl-selectfield__select
option(value='') option(value='')
each val in cocktails each val in cocktails
option(value=val[3])= val[2] + " - " + val[3] option(value=val[3])= val[2] + " - " + val[3]
label.mdl-selectfield__label(for='gender') New cocktail label.mdl-selectfield__label(for='cocktails') New cocktail
span.mdl-selectfield__error Select a value span.mdl-selectfield__error Select a value
.mdl-cell--3-col .mdl-cell--3-col
+rangemaker("pnew") +rangemaker("pnew")
.mdl-cell--3-col .mdl-cell--3-col
button.mdl-button.mdl-js-button.mdl-button--fab.mdl-js-ripple-effect button.mdl-button.mdl-js-button.mdl-button--fab.mdl-js-ripple-effect(onclick="sendNewCocktail()")
i.material-icons add i.material-icons add
//.mdl-card__actions.mdl-card--border //.mdl-card__actions.mdl-card--border
// a.mdl-button.mdl-button--colored.mdl-js-button.mdl-js-ripple-effect // a.mdl-button.mdl-button--colored.mdl-js-button.mdl-js-ripple-effect

View File

@@ -11,7 +11,7 @@ html
script(defer, type='text/javascript', src='/js/material.min.js') script(defer, type='text/javascript', src='/js/material.min.js')
script(defer, type='text/javascript', src='/js/mdl-selectfield.min.js') script(defer, type='text/javascript', src='/js/mdl-selectfield.min.js')
script(defer, type='text/javascript', src='/js/getmdl-select.min.js') script(defer, type='text/javascript', src='/js/getmdl-select.min.js')
script(defer, type='text/javascript', src='/js/custom.js') script(type='text/javascript', src='/js/custom.js')
body body
style. style.
.demo-layout-transparent { .demo-layout-transparent {
@@ -25,6 +25,19 @@ html
color: white; color: white;
} }
.demo-card-square.mdl-card {
width: 100%;
}
.demo-card-square > .mdl-card__title {
color: #fff;
background: #795548;
}
.mdl-selectfield__select option {
font-family: "Helvetica", "Arial", sans-serif;
}
.demo-layout-transparent.mdl-layout.mdl-js-layout .demo-layout-transparent.mdl-layout.mdl-js-layout
header.mdl-layout__header.mdl-layout__header--transparent header.mdl-layout__header.mdl-layout__header--transparent