Skip to content

Commit aee639e

Browse files
author
Anthony Gore
committed
First commit
0 parents  commit aee639e

17 files changed

+849
-0
lines changed

Diff for: .babelrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
["es2015"]
4+
],
5+
"plugins": ["transform-es2015-destructuring", "transform-object-rest-spread"]
6+
}

Diff for: .env_sample

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PORT=8000
2+
NODE_ENV=development
3+
IMDB_IDS=tt3748528,tt4501244,tt1711525,tt4682786,tt3183660,tt4034228,tt3783958,tt2543164,tt1211837,tt4550098

Diff for: .gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
node_modules/
3+
npm-debug.log
4+
.idea
5+
.env
6+
dist

Diff for: README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Ultimate Vue.js Developers Course
2+
3+
### Project 2: Vue.js Cinema
4+
5+
#### Demo
6+
7+
See the completed project here: [https://vuejs-cinema.getjsdojo.com/](https://vuejs-cinema.getjsdojo.com/)
8+
9+
#### Installation
10+
11+
1. Clone this repository on your local file system
12+
13+
```
14+
cd /path/to/install/location
15+
git clone [email protected]:getjsdojo/vuejs-cinema.git
16+
```
17+
18+
2. Install dependencies
19+
20+
```
21+
npm install
22+
```
23+
24+
3. Create a `.env` file by copying the sample
25+
26+
```
27+
cp .env_sample .env
28+
```
29+
30+
Edit the .env file and replace any variables if needed
31+
32+
4. Start project
33+
34+
```
35+
npm run start
36+
```
37+
38+
5. Your site will be available at *localhost:[PORT]* where `PORT` is whatever value is set in your `.env` file.

Diff for: api.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
require('dotenv').config();
2+
3+
const axios = require('axios');
4+
const async = require('async');
5+
const moment = require('moment-timezone');
6+
moment.tz.setDefault("UTC");
7+
8+
// Axios
9+
const $http = axios.create({
10+
baseURL: 'http://www.omdbapi.com/',
11+
});
12+
13+
function generateSessions(id) {
14+
let sessions = [];
15+
let nums = id.replace('tt', '').split('').map(item => parseInt(item));
16+
nums.forEach((num, index) => {
17+
let date = moment().startOf('day').add(index, 'days');
18+
for (let i = 0; i < num; i++) {
19+
let pos = index + i <= nums.length ? index + i : index + i - nums.length;
20+
let hours = nums[pos] + 12;
21+
let mins = nums[pos] < 2.5 ? 0 : nums[pos] < 5 ? 15 : nums[pos] < 7.5 ? 30 : 45;
22+
sessions.push({
23+
id: `${id}_${i}`,
24+
time: moment(date).add(hours, 'hours').add(mins, 'minutes'),
25+
seats: Math.round(200 - nums.reduce((acc, val) => { return acc + val; }) + (num * i))
26+
});
27+
}
28+
});
29+
return sessions.sort((a, b) => { if (a.time < b.time) { return - 1 } else { return a.time > b.time; } });
30+
}
31+
32+
module.exports = {
33+
getData(callback) {
34+
let ids = process.env.IMDB_IDS.split(',');
35+
let data = [];
36+
async.each(
37+
ids,
38+
function (id, callback) {
39+
if (!data.find(item => item.id === id)) {
40+
$http.get(`?i=${id}`)
41+
.then(
42+
function (response) {
43+
if (!response.data.Error) {
44+
data.push({
45+
id,
46+
movie: response.data,
47+
sessions: generateSessions(id)
48+
});
49+
data.sort((a, b) => { if (a.id < b.id) { return - 1 } else { return a.id > b.id; } });
50+
} else {
51+
console.log(response.data.Error);
52+
}
53+
callback();
54+
},
55+
function (err) {
56+
callback(err);
57+
}
58+
)
59+
;
60+
} else {
61+
callback();
62+
}
63+
},
64+
function(err) {
65+
if (err) {
66+
callback(err, null);
67+
} else {
68+
callback(null, data);
69+
}
70+
}
71+
);
72+
}
73+
};

Diff for: index.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Vue.js Cinema</title>
7+
<link rel="icon" href="/public/favicon.ico" type="image/x-icon">
8+
<link href="https://fonts.googleapis.com/css?family=Orbitron" rel="stylesheet">
9+
<style>
10+
[v-cloak] {
11+
display: none !important;
12+
}
13+
</style>
14+
</head>
15+
<body>
16+
<div id="app">
17+
<div id="title">
18+
<img src="/public/logo.png">
19+
<h1>Vue.js Cinema</h1>
20+
</div>
21+
</div>
22+
<script src="/dist/build.js"></script>
23+
</body>
24+
</html>

Diff for: package.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "vue-cinema",
3+
"version": "1.0.0",
4+
"description": "The Ultimate Vue.js Developers Course: Vue.js Cinema",
5+
"main": "server.js",
6+
"author": "Anthony Gore <[email protected]>",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/getjsdojo/vuejs-cinema"
10+
},
11+
"license": "UNLICENSED",
12+
"scripts": {
13+
"start": "nodemon ./server.js --ignore src/ -e js,html,css",
14+
"build": "rimraf dist && cross-env NODE_ENV=production webpack --progress --hide-modules"
15+
},
16+
"dependencies": {
17+
"async": "^2.1.4",
18+
"axios": "^0.15.3",
19+
"cross-env": "^3.1.3",
20+
"dotenv": "^2.0.0",
21+
"express": "^4.14.0",
22+
"nodemon": "^1.11.0"
23+
},
24+
"devDependencies": {
25+
"babel-core": "^6.0.0",
26+
"babel-loader": "^6.0.0",
27+
"babel-plugin-transform-es2015-destructuring": "^6.19.0",
28+
"babel-plugin-transform-object-rest-spread": "^6.20.2",
29+
"babel-preset-es2015": "^6.0.0",
30+
"cross-env": "^3.0.0",
31+
"css-loader": "^0.25.0",
32+
"file-loader": "^0.9.0",
33+
"moment": "^2.17.1",
34+
"moment-timezone": "^0.5.11",
35+
"node-sass": "^4.1.1",
36+
"open": "0.0.5",
37+
"sass-loader": "^4.1.1",
38+
"style-loader": "^0.13.1",
39+
"vue": "^2.1.0",
40+
"vue-loader": "^10.0.0",
41+
"vue-resource": "^1.0.3",
42+
"vue-router": "^2.1.1",
43+
"vue-style-loader": "^1.0.0",
44+
"vue-template-compiler": "^2.1.0",
45+
"webpack": "^2.1.0-beta.28",
46+
"webpack-dev-middleware": "^1.9.0",
47+
"webpack-hot-middleware": "^2.14.0"
48+
}
49+
}

Diff for: public/favicon.ico

1.12 KB
Binary file not shown.

Diff for: public/logo.png

6.96 KB
Loading

Diff for: server.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require('dotenv').config({ silent: true });
2+
3+
const express = require('express');
4+
const app = express();
5+
const path = require('path');
6+
const fs = require('fs');
7+
const api = require('./api');
8+
9+
if (process.env.NODE_ENV === 'development') {
10+
require('./webpack-dev-middleware').init(app);
11+
}
12+
13+
if (process.env.NODE_ENV === 'production') {
14+
app.use('/dist', express.static(path.join(__dirname, 'dist')));
15+
}
16+
17+
app.use('/public', express.static(path.join(__dirname, 'public')));
18+
19+
let template = fs.readFileSync(path.resolve('./index.html'), 'utf-8');
20+
app.get('/', function(req, res) {
21+
res.send(template);
22+
});
23+
24+
app.get('/api', function(req, res) {
25+
api.getData(function(err, data) {
26+
if (err) {
27+
res.status(500).send(err);
28+
} else {
29+
res.json({ data });
30+
}
31+
});
32+
});
33+
34+
app.listen(process.env.PORT, function () {
35+
console.log(`Example app listening on port ${process.env.PORT}!`);
36+
if (process.env.NODE_ENV === 'development') {
37+
require('open')(`http://localhost:${process.env.PORT}`);
38+
}
39+
});
40+

Diff for: src/main.js

Whitespace-only changes.

0 commit comments

Comments
 (0)