Skip to content

Commit 7821087

Browse files
committed
changes while integating with server
1 parent b6b28d7 commit 7821087

File tree

5 files changed

+52
-23
lines changed

5 files changed

+52
-23
lines changed

config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ module.exports = {
4141
env: {
4242
NODE_ENV: '"development"',
4343
RELEASE: '"development"',
44-
SOCKET_API_URL: '"api/"',
44+
// SOCKET_API_URL: '"api/"',
45+
SOCKET_API_URL: '"https://socket.tutorcruncher.com"',
4546
},
4647
port: 8000,
4748
build_dir: path.resolve(__dirname, 'dev'),

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
</main>
2525
</body>
2626
<script>
27-
socket()
27+
socket('115d3deb0a41c7b85d6c')
2828
</script>
2929
</html>

src/components/grid.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div id="tcs-grid">
33
<div v-for="contractor in contractors" class="tcs-col">
4-
<router-link :to="{name: 'modal', params: {slug: contractor.slug}}" class="tcs-box">
5-
<img :src="contractor.img" :alt="contractor.name">
4+
<router-link :to="{name: 'modal', params: {link: contractor.link}}" class="tcs-box">
5+
<img :src="contractor.photo" :alt="contractor.name">
66
<h3 class="tcs-name">{{ contractor.name }}</h3>
77
</router-link>
88
</div>
@@ -15,7 +15,7 @@ export default {
1515
name: 'grid',
1616
created: function () {
1717
// called here so get_data can be passed an argument for extra pages
18-
this.$root.get_data()
18+
this.$root.get_list()
1919
},
2020
data: function () {
2121
return {contractors: this.$root.contractors}

src/components/modal.vue

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,25 @@
2222
179l-364 774q-16 33-47.5 52t-67.5 19-67.5-19-46.5-52l-365-774q-33-70-33-179 0-212 150-362t362-150
2323
362 150 150 362z"/>
2424
</svg>
25-
<span>{{ contractor.location }}</span>
25+
<span>{{ contractor.town }}, {{ contractor.country }}</span>
2626
</div>
2727

2828
<div class="tcs-aside">{{ contractor.tag_line }}</div>
29-
<div v-for="text_attribute in contractor.text_attributes">
30-
<h3>{{ text_attribute.name }}</h3>
31-
{{ text_attribute.value }}
29+
30+
<div>
31+
{{ contractor.primary_description }}
32+
</div>
33+
34+
<div v-for="attr in contractor_extra.extra_attributes">
35+
<h3>{{ attr.name }}</h3>
36+
{{ attr.value }}
3237
</div>
3338

34-
<table class="tcs-skills" v-if="contractor.skills">
39+
<table class="tcs-skills" v-if="contractor_extra.skills">
3540
<caption>
3641
<h3>{{ $root.config.skills_label }}</h3>
3742
</caption>
38-
<tr v-for="skill in contractor.skills">
43+
<tr v-for="skill in contractor_extra.skills">
3944
<th scope="row">{{ skill.subject }}</th>
4045
<td>
4146
<span v-for="qual_level in skill.qual_levels">
@@ -46,14 +51,17 @@
4651
</table>
4752
</div>
4853
<div class="tcs-extra">
49-
<img :src="contractor.img" :alt="contractor.name">
54+
<img :src="contractor.photo" :alt="contractor.name">
5055
<!--<button>Contact {{ contractor.name }}</button>-->
5156
<p v-html="contact_html"></p>
5257
</div>
5358
</div>
5459
</div>
5560

5661
</div>
62+
<div v-else class="tcs-container">
63+
<p>Could not find contractor.</p>
64+
</div>
5765
</div>
5866
</transition>
5967
</template>
@@ -68,13 +76,17 @@ export default {
6876
},
6977
computed: {
7078
contractor: function () {
71-
// return _.find(this.$root.contractors, {'slug': this.$route.params.slug})
7279
for (var contractor of this.$root.contractors) {
73-
if (contractor.slug === this.$route.params.slug) {
80+
if (contractor.link === this.$route.params.link) {
81+
console.log('con', contractor)
82+
this.$root.get_details(contractor.url, contractor.link)
7483
return contractor
7584
}
7685
}
7786
},
87+
contractor_extra: function () {
88+
return this.$root.contractors_extra[this.$route.params.link] || {}
89+
},
7890
contact_html: function () {
7991
let raw = this.$root.config.contact_html
8092
return raw.replace('{name}', this.contractor.name).replace('{contact_link}', this.$root.config.contact_link)
@@ -142,7 +154,7 @@ $back-colour: 35;
142154
.tcs-location {
143155
margin-bottom: 10px;
144156
float: right;
145-
$svg-size: 24px;
157+
$svg-size: 22px;
146158
svg {
147159
width: $svg-size;
148160
height: $svg-size;

src/main.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const ConfiguredVueRouter = config => new VueRouter({
2020
component: grid,
2121
children: [
2222
{
23-
path: '/:slug',
23+
path: '/:link',
2424
name: 'modal',
2525
component: modal,
2626
}
@@ -29,7 +29,7 @@ const ConfiguredVueRouter = config => new VueRouter({
2929
]
3030
})
3131

32-
module.exports = function (config) {
32+
module.exports = function (public_key, config) {
3333
config = config || {}
3434

3535
if (config.api_root === undefined) {
@@ -62,17 +62,19 @@ module.exports = function (config) {
6262
render: h => h(app),
6363
data: {
6464
contractors: [],
65+
contractors_extra: {},
6566
config: config,
6667
error: null,
68+
public_key: public_key,
6769
},
6870
components: {
6971
app
7072
},
7173
methods: {
7274
// get_data is called by components, eg. grid
73-
get_data: function () {
75+
get_list: function () {
7476
let xhr = new window.XMLHttpRequest()
75-
let url = config.api_root + '/contractors.json'
77+
let url = `${config.api_root}/${public_key}/contractors`
7678
xhr.open('GET', url)
7779
xhr.onload = () => {
7880
let contractors
@@ -83,9 +85,7 @@ module.exports = function (config) {
8385
contractors = JSON.parse(xhr.responseText)
8486
}
8587
this.contractors.splice(0)
86-
contractors.forEach(con => {
87-
this.contractors.push(con)
88-
})
88+
contractors.forEach(con => this.contractors.push(con))
8989
} catch (e) {
9090
this.error = `\
9191
${e.toString()}
@@ -101,10 +101,26 @@ ${xhr.responseText}`
101101
Connection error
102102
requested url: "${url}"
103103
response status: ${xhr.status}
104-
response text: "${xhr.responseText}"`
104+
response text: "${xhr.responseText}"`
105105
Raven.captureException(new Error(this.error))
106106
}
107107
xhr.send()
108+
},
109+
get_details: function (url, link) {
110+
if (this.contractors_extra[link] !== undefined) {
111+
return
112+
}
113+
let xhr = new window.XMLHttpRequest()
114+
xhr.open('GET', url)
115+
xhr.onload = () => {
116+
if (xhr.status !== 200) {
117+
throw new Error(`bad response ${xhr.status}`)
118+
} else {
119+
let con = JSON.parse(xhr.responseText)
120+
Vue.set(this.contractors_extra, link, con)
121+
}
122+
}
123+
xhr.send()
108124
}
109125
}
110126
})

0 commit comments

Comments
 (0)