Skip to content

Commit

Permalink
Merge pull request #4 from AskToni/restaurant-details
Browse files Browse the repository at this point in the history
Restaurant details
  • Loading branch information
RedTn committed Sep 30, 2017
2 parents 7acb489 + 0f3898c commit 9ffd2c0
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 13 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
},
"dependencies": {
"axios": "^0.16.2",
"leaflet": "^1.2.0",
"leaflet.icon.glyph": "^0.2.0",
"sass-loader": "^6.0.6",
"style-loader": "^0.18.2",
"vue": "^2.3.3",
"vue-material": "^0.7.4",
"vue-material": "^0.7.5",
"vue-router": "^2.6.0"
},
"devDependencies": {
Expand Down Expand Up @@ -101,6 +103,7 @@
"vue-loader": "^12.1.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.3.3",
"vue2-leaflet": "^0.0.53",
"webpack": "^2.6.1",
"webpack-bundle-analyzer": "^2.2.1",
"webpack-dev-middleware": "^1.10.0",
Expand Down
174 changes: 174 additions & 0 deletions src/components/RestaurantDetail.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<template>
<div class="restaurantDetail">
<md-spinner :md-size="150" md-indeterminate v-if="isLoading" style="height: 85vh;"></md-spinner>
<md-layout v-else>
<md-layout md-column md-flex-medium="100" style="height: calc(100vh - 64px);">
<md-layout md-flex="50">
<md-card class="md-flex">
<md-card-header>
<div class="md-title">{{model.restaurantName}}</div>
</md-card-header>

<md-card-content>
<md-list class="md-double-line">
<md-list-item>
<md-layout>
<md-layout md-column>{{model.address}}</md-layout>
<md-layout md-column>{{model.city}}</md-layout>
<md-layout md-column><a :href="hrefPhone">{{hrefPhone}}</a></md-layout>
</md-layout>
<md-divider></md-divider>
</md-list-item>
<md-list-item>
<div class="md-list-text-container">
<span>Price</span>
<span>{{model.price}}</span>
</div>
<div class="md-list-text-container">
<span>Rating</span>
<span>{{model.rating}}</span>
</div>
<md-divider></md-divider>
</md-list-item>
<md-list-item>
<div class="md-list-text-container">
<span>Categories</span>
<md-layout>
<div v-for="(chip, index) in model.categories" :key="index">
<md-chip class="md-primary">{{chip}}</md-chip>
</div>
</md-layout>
</div>
<md-divider></md-divider>
</md-list-item>
</md-list>
</md-card-content>
</md-card>
</md-layout>
<md-layout md-flex="50">
<md-card class="md-flex">

<md-card-content style="height: 100%">
<v-map :zoom="zoom" :center="center" :min-zoom="minZoom" :max-zoom="maxZoom">
<v-tilelayer :url="url"></v-tilelayer>
<v-marker :lat-lng="marker"></v-marker>
<v-icondefault :image-path="path"></v-icondefault>
</v-map>
</md-card-content>

<md-card-actions>
<md-button :href="hrefGoogle" class="md-raised md-primary">Find On Google</md-button>
</md-card-actions>
</md-card>
</md-layout>
</md-layout>
<md-layout md-column md-flex-medium="100" style="height: calc(100vh - 64px);" class="renderedLayout">
<md-layout>
<md-card class="md-flex">
<md-card-header>
<div class="md-title">Reviews ({{model.reviewCount}})</div>
</md-card-header>

<md-card-content>
<md-list>
<md-list-item v-for="(review, index) in reviews" :key="index">
<md-rating-bar v-model="review.rating" class="md-primary" disabled></md-rating-bar>
<span>{{review.text.slice(0, 50)}}...</span>

<md-list-expand>
{{review.text}}
</md-list-expand>
</md-list-item>
</md-list>
</md-card-content>
</md-card>
</md-layout>
</md-layout>
</md-layout>
</div>
</template>

<script>
import Vue2Leaflet from 'vue2-leaflet';
import axios from 'axios';
/* global L */
const leaflet = L;
// const corner1 = leaflet.latLng(46.2, -118.6);
// const corner2 = leaflet.latLng(45.9, -118.1);
export default {
name: 'example',
components: {
'v-map': Vue2Leaflet.Map,
'v-tilelayer': Vue2Leaflet.TileLayer,
'v-marker': Vue2Leaflet.Marker,
'v-icondefault': Vue2Leaflet.IconDefault
},
computed: {
hrefPhone() {
return `tel:${this.model.phone.slice(0, 2)}-${this.model.phone.slice(2, 5)}-${this.model.phone.slice(5, 8)}-${this.model.phone.slice(8, 12)}`;
},
hrefGoogle() {
return `https://www.google.com/maps/?q=${this.model.latitude},${this.model.longitude}`;
}
},
data() {
return {
zoom: 16,
center: leaflet.latLng(0, 0),
url: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
marker: leaflet.latLng(0, 0),
path: '/static/',
// maxBounds: leaflet.latLngBounds(corner1, corner2),
maxZoom: 18,
minZoom: 13,
isLoading: true,
reviews: []
};
},
methods: {
async getModel() {
try {
this.isLoading = true;
const response = await axios.get(`http://asktoniapi.azurewebsites.net/api/Restaurant/${this.$route.params.id}`);
this.model = response.data;
this.center = leaflet.latLng(this.model.latitude, this.model.longitude);
this.marker = leaflet.latLng(this.model.latitude, this.model.longitude);
this.reviews = await Promise.all(this.model.reviewIDs.map(async (reviewID) => {
const reviewResponse = await axios.get(`http://asktoniapi.azurewebsites.net/api/Review/${reviewID}`);
return Object.assign({}, { show: true }, reviewResponse.data);
}));
this.isLoading = false;
} catch (e) {
console.error(e);
}
}
},
created() {
this.getModel();
}
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
@import "../../node_modules/leaflet/dist/leaflet.css";
.restaurantDetail /deep/ {
.leaflet-pane, .leaflet-top.leaflet-left {
z-index: 1;
}
.leaflet-control-attribution.leaflet-control {
display: none;
}
.md-card {
margin: 15px;
}
.md-list-item {
.md-full-icon {
padding-top: 6px;
}
}
}
</style>
21 changes: 14 additions & 7 deletions src/components/Restaurants.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@

<md-table-body>
<md-table-row v-for="(row, rowIndex) in tableRows" :key="rowIndex" :md-item="row">
<md-table-cell v-for="(column, columnIndex) in row" :key="columnIndex" v-if="renderedColumns[columnIndex]">
{{ column }}
<md-table-cell v-for="(column, key) in row" :key="key" v-if="renderedColumns[key]">
<span v-if="key !== 'restaurantName'">
{{ column }}
</span>
<span v-else>
<router-link :to="'restaurant/' + row.id">{{ column }}</router-link>
</span>
</md-table-cell>
</md-table-row>
</md-table-body>
Expand All @@ -55,7 +60,7 @@ export default {
renderedColumns() {
const renderedColumns = {};
this.columns.forEach((column) => {
renderedColumns[column.value] = 1;
renderedColumns[column.value] = true;
});
return renderedColumns;
},
Expand Down Expand Up @@ -161,9 +166,11 @@ export default {

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.restaurants /deep/ .md-table-head-container{
display: flex;
align-items: center;
justify-content: center;
.restaurants /deep/ {
.md-table-head-container, .md-has-action .md-table-cell-container {
display: flex;
align-items: center;
justify-content: center;
}
}
</style>
6 changes: 6 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Vue from 'vue';
import Router from 'vue-router';
import Index from '@/components/Index';
import Restaurants from '@/components/Restaurants';
import RestaurantDetail from '@/components/RestaurantDetail';
import Reviews from '@/components/Reviews';
import Users from '@/components/Users';

Expand All @@ -14,6 +15,11 @@ export default new Router({
name: 'Restaurants',
component: Restaurants
},
{
path: '/restaurant/:id',
name: 'Restaurant Detail',
component: RestaurantDetail
},
{
path: '/index',
name: 'Index',
Expand Down
Binary file added static/layers-2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/layers.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/marker-icon-2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/marker-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/marker-shadow.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions test/unit/specs/RestaurantDetail.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import Vue from 'vue';
import RestaurantDetail from '@/components/RestaurantDetail';
import VueMaterial from 'vue-material';
import 'vue-material/dist/vue-material.css';

function setup() {
Vue.use(VueMaterial);

Vue.material.registerTheme({
default: {
primary: 'blue',
accent: 'pink'
},
blue: {
primary: 'blue',
accent: 'pink'
},
indigo: {
primary: 'indigo',
accent: 'pink'
},
brown: {
primary: 'brown',
accent: 'green'
},
purple: {
primary: 'purple',
accent: 'blue'
},
orange: {
primary: 'orange',
accent: 'purple'
},
green: {
primary: 'green',
accent: 'pink'
},
'light-blue': {
primary: 'light-blue',
accent: 'yellow'
},
teal: {
primary: 'teal',
accent: 'orange'
},
'blue-grey': {
primary: 'blue-grey',
accent: 'blue'
},
cyan: {
primary: 'cyan',
accent: 'pink'
},
red: {
primary: 'red',
accent: 'pink'
},
white: {
primary: 'white',
accent: 'blue'
},
grey: {
primary: {
color: 'grey',
hue: 300
},
accent: 'indigo'
}
});

Vue.material.setCurrentTheme('default');
}

describe('RestaurantDetail.vue', () => {
setup();
it('has a created hook', () => {
expect(typeof RestaurantDetail.created).to.equal('function');
});
// it('should render correct contents', () => {
// const Constructor = Vue.extend(RestaurantDetail);
// const vm = new Constructor().$mount();
// expect(vm.$el.querySelector('.restaurants .md-title').textContent)
// .to.equal('Restaurants');
// });
});
27 changes: 22 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3741,6 +3741,14 @@ lcid@^1.0.0:
dependencies:
invert-kv "^1.0.0"

leaflet.icon.glyph@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/leaflet.icon.glyph/-/leaflet.icon.glyph-0.2.0.tgz#aadf17d4399819973aae2124b321676d8c5d33d9"

leaflet@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.2.0.tgz#fd5d93d9cb00091f5f8a69206d0d6744c1c82697"

leven@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/leven/-/leven-2.1.0.tgz#c2e7a9f772094dee9d34202ae8acce4687875580"
Expand Down Expand Up @@ -6552,11 +6560,9 @@ vue-loader@^12.1.0:
vue-style-loader "^3.0.0"
vue-template-es2015-compiler "^1.2.2"

vue-material@^0.7.4:
version "0.7.4"
resolved "https://registry.yarnpkg.com/vue-material/-/vue-material-0.7.4.tgz#51ac621a3fceeba3ea49ffe0858c0b45785efe10"
dependencies:
vue "^2.3.3"
vue-material@^0.7.5:
version "0.7.5"
resolved "https://registry.yarnpkg.com/vue-material/-/vue-material-0.7.5.tgz#045517403c1338aceabd73030f3dd6b5c744fe55"

vue-router@^2.6.0:
version "2.7.0"
Expand All @@ -6580,6 +6586,17 @@ vue-template-es2015-compiler@^1.2.2:
version "1.5.3"
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.5.3.tgz#22787de4e37ebd9339b74223bc467d1adee30545"

vue2-leaflet@^0.0.53:
version "0.0.53"
resolved "https://registry.yarnpkg.com/vue2-leaflet/-/vue2-leaflet-0.0.53.tgz#07f2975a0a75918c122545ed913e1e153fec8f80"
dependencies:
leaflet "^1.2.0"
vue "^2.0.0-rc.8"

vue@^2.0.0-rc.8:
version "2.4.4"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.4.4.tgz#ea9550b96a71465fd2b8b17b61673b3561861789"

vue@^2.3.3:
version "2.4.2"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.4.2.tgz#a9855261f191c978cc0dc1150531b8d08149b58c"
Expand Down

0 comments on commit 9ffd2c0

Please sign in to comment.