-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
129 lines (117 loc) · 3.34 KB
/
app.js
File metadata and controls
129 lines (117 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var express = require("express");
var app = express();
var expressHandlebars = require("express-handlebars").create({
defaultLayout: "main"
});
var bodyParser = require("body-parser");
var multer = require("multer");
var upload = multer({ dest: "uploads/" });
var path = require("path");
app.engine("handlebars", expressHandlebars.engine);
app.set("view engine", "handlebars");
app.set("port", 3000);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use("/static", express.static(path.join(__dirname, "public")));
// sample data to populate the application
var forms = [
{
name: "Media Reviews",
desc: "Content intake form for product media reviews.",
id: 0,
inputs: {
modelNumbers: "Model Numbers",
publication: "Publication",
title: "Title",
body: "Body",
linkURL: "Link URL"
}
},
{
name: "Video Overviews",
desc: "Content intake form for video overviews.",
id: 1,
inputs: {
videoTitle: "Video Title",
bodyCopy: "Body Copy",
videoURL: "Video URL"
}
},
{
name: "Product Features",
desc: "Content intake form for product features.",
id: 2,
inputs: {
type: "Type",
tItle: "TItle",
body: "Body",
linkName: "Link Name",
linkURL: "Link URL"
}
}
];
var completedForms = [
{
name: "Media Reviews",
desc: "Content intake form for product media reviews.",
time: "Sat Nov 23 2019 15:44:36 GMT-0600 (CST)",
id: 0,
inputs: {
modelNumbers: "52241",
publication: "Cycling Tips",
title: "A fast and fun ride",
body:
"The new Domane is better than ever, with improved handling and increased comfort",
linkURL: "cyclingtips.com"
}
},
{
name: "Video Overviews",
desc: "Content intake form for video overviews.",
time: "Sat Nov 23 2019 15:46:33 GMT-0600 (CST)",
id: 1,
inputs: {
videoTitle: "How To: Change Your Tires",
bodyCopy:
"Changing your bike tires is a regular part of maintaining your bike. Here we provide you with a video that explains the entire process.",
videoURL: "www.youtube.com"
}
}
];
app.get("/", function(req, res) {
res.render("landing");
});
app.get("/forms", function(req, res) {
res.render("forms", { forms: forms });
});
app.get("/forms/new", function(req, res) {
res.render("admin");
});
app.post("/forms", upload.fields([]), function(req, res) {
var position = forms.length;
forms.push(req.body);
forms[position].id = position;
res.redirect("forms");
});
app.get("/forms/view", function(req, res) {
var id = req.query.id;
var formItem = forms[id];
res.render("view", { formItem: JSON.stringify(formItem) });
});
app.post("/forms/view", upload.fields([]), function(req, res) {
var position = completedForms.length;
completedForms.push(req.body);
completedForms[position].id = position;
res.redirect("../forms/completed");
});
app.get("/forms/completed", function(req, res) {
res.render("completed", { completedForms: completedForms });
});
app.get("/forms/completed/view_completed", function(req, res) {
var id = req.query.id;
var formItem = completedForms[id];
res.render("view_completed", { formItem: JSON.stringify(formItem) });
});
app.listen(app.get("port"), function() {
console.log("Express started on http://localhost:" + app.get("port") + ".");
});