Skip to content

Commit 295b4fc

Browse files
committed
feat(helper functions) + update readme
1 parent 34f5301 commit 295b4fc

File tree

10 files changed

+40
-27
lines changed

10 files changed

+40
-27
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
APP_ENV="production"
2+
API_ONLY=false
23

34
API_PROTOCOL="http"
45
API_HOST="localhost"

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ npm run serve:prod
2222
The server starts by default on port `3000`. To launch app with other port, or define other environment variables, you can edit `.env` file.
2323
```
2424
APP_ENV="production"
25+
API_ONLY=false
2526
2627
API_PROTOCOL="http"
2728
API_HOST="localhost"
@@ -35,4 +36,7 @@ CONF_PATH="/etc/apache2/"
3536
CONF_EXTENSION=".conf"
3637
CONF_AVAILABLES="sites-available/"
3738
CONF_ENABLED="sites-enabled/"
38-
```
39+
```
40+
41+
If you only want to launch the API, you can set `API_ONLY` env variable value at `true`.
42+
It allows you to access the app via an HTTP server like Apache2, Nginx etc (the entry point is `build/index.html`).

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ api.put('/api/vh/:id/disable', async (req, res) => {
131131

132132
api.listen(config.api.port, () => console.log(`API started on ${config.api.protocol}://${config.api.host}:${config.api.port}`))
133133

134-
if (env === 'production') {
134+
if (env === 'production' && process.env.API_ONLY === false) {
135135
const app = express()
136136
app.use(express.static(__dirname + '/dist/'));
137137
app.get('/', (req, res) => res.sendFile(__dirname + '/dist/index.html'))

src/components/Actions.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ export default {
5353
try {
5454
const id = this.item.id
5555
const info = await VHMaganer.duplicate(id)
56-
this.$root.$emit('vh.duplicated', { id, info })
57-
this.$root.$emit('flash', { message: "VHost dupliqué avec succès", type: 'success' })
56+
dispatch('vh.duplicated', { id, info })
57+
flash("VHost dupliqué avec succès", "success")
5858
} catch (e) {
59-
this.$root.$emit('flash', { message: e })
59+
flash(e)
6060
}
6161
},
6262
@@ -65,10 +65,10 @@ export default {
6565
try {
6666
const id = this.item.id
6767
await VHMaganer.destroy(id)
68-
this.$root.$emit('vh.destroyed', { id })
69-
this.$root.$emit('flash', { message: "VHost supprimé avec succès", type: 'success' })
68+
dispatch('vh.destroyed', { id })
69+
flash("VHost supprimé avec succès", "success")
7070
} catch (e) {
71-
this.$root.$emit('flash', { message: e })
71+
flash(e)
7272
}
7373
},
7474
@@ -82,7 +82,7 @@ export default {
8282
} catch (e) {
8383
message = e
8484
}
85-
this.$root.$emit('flash', { message, type })
85+
flash(message, type)
8686
}
8787
},
8888

src/components/FlashComponent/FlashContainer.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export default {
3838
},
3939
4040
mounted () {
41-
this.$root.$on('flash', this.addItem.bind(this))
42-
this.$root.$on('flash.close', ({ id }) => this.removeItem(id))
41+
this.$nextTick(() => {
42+
listen('flash', this.addItem.bind(this))
43+
listen('flash.close', ({ id }) => this.removeItem(id))
44+
})
4345
}
4446
}
4547
</script>

src/components/Form.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default {
9898
this.item = {...this.item, ...response}
9999
this.initEditor(this.parsed)
100100
} catch (e) {
101-
this.$root.$emit('flash', { message: e })
101+
flash(e)
102102
}
103103
},
104104
@@ -129,7 +129,7 @@ export default {
129129
let message = 'VHost %s avec succès'
130130
let state = this.editing ? 'mis à jour' : 'créé'
131131
if (enabled) state = `${state} et activé`
132-
this.$root.$emit('flash', { message: message.replace('%s', state), type: 'success' })
132+
flash(message.replace('%s', state), 'success')
133133
} catch (e) {
134134
this.configtest = e.message ? e.message : e
135135
this.lineError = VHMaganer.getLineError(this.configtest)
@@ -160,7 +160,10 @@ export default {
160160
} catch (e) {
161161
if (this.hasConfigError) {
162162
this.lineError = VHMaganer.getLineError(e)
163-
if (this.lineError !== null) this.editor.addLineClass(this.lineError, 'wrap', 'error__bg')
163+
if (this.lineError !== null) {
164+
this.editor.addLineClass(this.lineError, 'wrap', 'error__bg')
165+
this.editor.scrollIntoView(this.lineError)
166+
}
164167
}
165168
}
166169
this.loader = false
@@ -241,7 +244,7 @@ export default {
241244
position: relative;
242245
243246
&.has__error .CodeMirror {
244-
padding-bottom: 50px;
247+
padding-bottom: 60px;
245248
246249
.CodeMirror-scroll {
247250
overflow: hidden !important;
@@ -273,10 +276,10 @@ export default {
273276
width: 100%;
274277
font-size: .85em;
275278
font-style: italic;
276-
height: 50px;
279+
max-height: 60px;
277280
margin: 0;
278-
padding: .25em 1em;
279-
background-color: transparent;
281+
padding: .5em 1em;
282+
background-color: $bg-color;
280283
transform: translateY(-20px);
281284
z-index: 100;
282285
overflow-y: auto;

src/components/Home.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export default {
5252
this.list = await VHMaganer.all()
5353
this.filteredList = this.list
5454
} catch (e) {
55-
this.$root.$emit('flash', { message: e })
55+
// this.$root.$emit('flash', { message: e })
56+
flash(e)
5657
}
5758
this.loader = false
5859
},
@@ -80,8 +81,8 @@ export default {
8081
8182
async mounted () {
8283
await this.fetchList()
83-
this.$root.$on('vh.duplicated', ({ info }) => this.filteredList.push(info))
84-
this.$root.$on('vh.destroyed', ({ id }) => this.filteredList = this.filteredList.filter(item => item.id != id))
84+
listen('vh.duplicated', ({ info }) => this.filteredList.push(info))
85+
listen('vh.destroyed', ({ id }) => this.filteredList = this.filteredList.filter(item => item.id != id))
8586
}
8687
}
8788
</script>

src/components/Show.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Loader v-show="loader" />
44
<div v-show="!loader && item">
55
<div class="toolbar toolbar__show">
6-
<router-link class="toolbar__link back__link" :to="{ name: 'vh.index'}">Retour</router-link>
6+
<router-link class="toolbar__link back__link" :to="{ name: 'vh.index' }">Retour</router-link>
77
<Actions :item="item" class="toolbar__actions" />
88
</div>
99
<div class="info">
@@ -45,7 +45,7 @@ export default {
4545
try {
4646
this.item = await VHMaganer.find(this.$route.params.id)
4747
} catch (e) {
48-
this.$root.$emit('flash', { message: e })
48+
flash(e)
4949
}
5050
this.loader = false
5151
}

src/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// The Vue build version to load with the `import` command
2-
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
31
import Vue from 'vue'
42
import App from './App'
53
import router from './router'
@@ -12,9 +10,13 @@ Vue.filter('join', function (value, glue = ', ') {
1210
})
1311

1412
/* eslint-disable no-new */
15-
new Vue({
13+
const app = new Vue({
1614
el: '#app',
1715
router,
1816
components: { App },
1917
template: '<App/>'
2018
})
19+
20+
window.listen = (name, cb) => app.$root.$on(name, cb)
21+
window.dispatch = (name, data = {}) => app.$root.$emit(name, data)
22+
window.flash = (message, type, timeout) => dispatch('flash', { message, type, timeout })

static/scss/_variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ $black-color: #000;
33
$dark-color: #2b2828;
44
$main-color: #ae18ae;
55
$text-color: #4d4d4d;
6-
$bg-color: #ddd;
6+
$bg-color: #282a36;
77
$success-color: #26A65B;
88
$error-color: #D64541;

0 commit comments

Comments
 (0)