@silexlabs/silex-dashboard 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.silex-client.js CHANGED
@@ -1,26 +1,24 @@
1
1
  import templatePlugin from '/node_modules/@silexlabs/silex/dist/plugins/client/plugins/client/template.js'
2
- import publishTo from '/node_modules/@silexlabs/silex/dist/plugins/client/plugins/client/publicationRenderer.js'
2
+ import publicationRenderer from '/node_modules/@silexlabs/silex/dist/plugins/client/plugins/client/publicationRenderer.js'
3
3
 
4
4
  export default async function(config, options) {
5
- console.log('silex-client.js', templatePlugin)
6
5
  // Defaults
7
6
  const opts = {
8
7
  ...options,
9
8
  }
10
9
  await config.addPlugin(templatePlugin)
11
- await config.addPlugin(publishTo, {
12
- publishTo: 'https://silex.me/publish',
10
+ await config.addPlugin(publicationRenderer, {
13
11
  css: {
14
12
  frontMatter: true,
15
13
  ext: '.css.liquid',
16
- path: '../../pages'
14
+ path: '../../../pages'
17
15
  },
18
16
  html: {
19
17
  frontMatter: false,
20
- path: '../../_includes'
18
+ path: '../../../_includes'
21
19
  },
22
20
  assets: {
23
- path: '../../',
21
+ path: '../../../',
24
22
  url: '/',
25
23
  },
26
24
  })
package/.silex.js CHANGED
@@ -5,8 +5,17 @@ const node_modules = require('node_modules-path')
5
5
  const serveStatic = require('serve-static')
6
6
  const locale = require('locale')
7
7
  const { withCache } = require('@silexlabs/silex/dist/plugins/server/plugins/server/Cache')
8
+ const { ServerEvent } = require('@silexlabs/silex').events
9
+
10
+ const { ConnectorType } = require('@silexlabs/silex/dist/server/types')
11
+ const FtpConnector = require('@silexlabs/silex/dist/plugins/server/plugins/server/FtpConnector').default
12
+ const GitlabConnector = require('@silexlabs/silex/dist/plugins/server/plugins/server/GitlabConnector').default
13
+ const {FsStorage} = require('@silexlabs/silex/dist/server/server/connectors/FsStorage')
14
+ const {FsHosting} = require('@silexlabs/silex/dist/server/server/connectors/FsHosting')
8
15
 
9
16
  module.exports = async function(config, options) {
17
+ console.log('> Silex dashboard plugin starting', {config, options})
18
+
10
19
  // Defaults
11
20
  const opts = {
12
21
  defaultLanguage: 'en',
@@ -14,11 +23,33 @@ module.exports = async function(config, options) {
14
23
  ...options,
15
24
  }
16
25
 
26
+ config.addHostingConnector([
27
+ new FsHosting(config, {
28
+ path: process.env.SILEX_FS_ROOT,
29
+ }),
30
+ new FtpConnector(config, {
31
+ type: ConnectorType.HOSTING,
32
+ }),
33
+ ])
34
+
35
+ //config.addStorageConnector([
36
+ // //new FsStorage(config, {
37
+ // // path: process.env.SILEX_FS_ROOT,
38
+ // //}),
39
+ // new FtpConnector(config, {
40
+ // type: ConnectorType.STORAGE,
41
+ // }),
42
+ // new GitlabConnector(config, {
43
+ // clientId: process.env.GITLAB_CLIENT_ID,
44
+ // clientSecret: process.env.GITLAB_CLIENT_SECRET,
45
+ // }),
46
+ //])
47
+
17
48
  // Detect language from browser
18
49
  const languages = JSON.parse(await fs.readFile(join(__dirname, '_data/languages.json')))
19
50
 
20
51
  // Serve the dashboard and the editor
21
- config.on('silex:startup:start', ({app}) => {
52
+ config.on(ServerEvent.STARTUP_START, ({app}) => {
22
53
  const router = express.Router()
23
54
  app.use(router)
24
55
 
@@ -38,6 +69,7 @@ module.exports = async function(config, options) {
38
69
 
39
70
  // Serve the editor when the ?id param is present in the URL
40
71
  const editorRouter = express.Router()
72
+ console.log('> Silex dashboard on route /', {opts})
41
73
  editorRouter.use('/', (req, res, next) => {
42
74
  if (req.path === '/' && !req.query.id) res.redirect(`/${req.locale}/`)
43
75
  else next()
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "en": {
3
+ "Failed to start dashboard": "Failed to start dashboard",
3
4
  "Failed to fetch websites": "Failed to fetch websites",
4
5
  "HTTP error! status: ${response.status}": "HTTP error! status: ${response.status}",
5
6
  "You need to provide a website name": "You need to provide a website name",
@@ -9,9 +10,17 @@
9
10
  "Website deleted successfully": "Website deleted successfully",
10
11
  "Failed to delete website": "Failed to delete website",
11
12
  "New name for this website": "New name for this website",
12
- "Website renamed successfully": "Website renamed successfully"
13
+ "Website renamed successfully": "Website renamed successfully",
14
+ "Failed to rename website": "Failed to rename website",
15
+ "Login failed": "Error, login failed.",
16
+ "Logout": "Logout",
17
+ "Logging out": "Logging out",
18
+ "Back to home": "< Back",
19
+ "Welcome to Silex": "Welcome to Silex",
20
+ "Please login to continue": "Please login to continue"
13
21
  },
14
22
  "fr": {
23
+ "Failed to start dashboard": "Erreur, impossible de démarrer le tableau de bord",
15
24
  "Failed to fetch websites": "Erreur, impossible de récupérer la liste des sites",
16
25
  "HTTP error! status: ${response.status}": "Erreur HTTP ! status: ${response.status}",
17
26
  "You need to provide a website name": "Vous n\\'avez pas donné de nom à votre site",
@@ -21,6 +30,13 @@
21
30
  "Website deleted successfully": "Le site a bien été effacé",
22
31
  "Failed to delete website": "Erreur, le site n\\'a pas été effacé",
23
32
  "New name for this website": "Nouveau nom",
24
- "Website renamed successfully": "Changement de nom effectué"
33
+ "Website renamed successfully": "Changement de nom effectué",
34
+ "Failed to rename website": "Erreur, le nom n\\'a pas été changé",
35
+ "Login failed": "Erreur, impossible de se connecter.",
36
+ "Logout": "Déconnexion",
37
+ "Logging out": "Déconnexion en cours",
38
+ "Back to home": "< Retour",
39
+ "Welcome to Silex": "Bienvenue sur Silex",
40
+ "Please login to continue": "Merci de vous connecter pour continuer"
25
41
  }
26
42
  }
@@ -9,6 +9,7 @@ window.addEventListener('load', function() {
9
9
  } = types
10
10
  const {
11
11
  connectorList,
12
+ logout,
12
13
  } = api
13
14
 
14
15
  const App = {
@@ -18,10 +19,16 @@ window.addEventListener('load', function() {
18
19
  error: null,
19
20
  message: null,
20
21
  loading: true,
22
+ lastConnector: null,
21
23
  }
22
24
  },
23
25
  mounted() {
24
26
  this.init()
27
+ window.addEventListener('message', (event) => {
28
+ if(event.data && event.data.type === 'login') {
29
+ this.loginResult(event.data)
30
+ }
31
+ })
25
32
  },
26
33
 
27
34
  methods: {
@@ -29,7 +36,7 @@ window.addEventListener('load', function() {
29
36
  try {
30
37
  this.loading = true
31
38
  console.log('init')
32
- this.connectors = await connectorList()
39
+ this.connectors = await connectorList({type: ConnectorType.STORAGE})
33
40
  console.log('connectors', this.connectors)
34
41
  this.loading = false
35
42
  } catch (error) {
@@ -38,6 +45,38 @@ window.addEventListener('load', function() {
38
45
  this.loading = false
39
46
  }
40
47
  },
48
+ openLogin(connector) {
49
+ this.lastConnector = connector
50
+ const nonOAuthUrl = `${constants.API_PATH}${constants.API_CONNECTOR_PATH}${constants.API_CONNECTOR_LOGIN}?connectorId=${connector.connectorId}&type=${connector.type}`
51
+ console.log('openLogin', connector.oauthUrl, nonOAuthUrl)
52
+ window.open(connector.oauthUrl || nonOAuthUrl, '_blank')
53
+ },
54
+ loginResult(data) {
55
+ console.log('loginResult', data)
56
+ if(data.error) {
57
+ this.error = data.error
58
+ this.message = `{{ api-translations[lang]["Login failed"] }} ${data.message}`
59
+ } else {
60
+ window.location.href = '/'
61
+ }
62
+ },
63
+ async logout() {
64
+ try {
65
+ this.message = '{{ api-translations[lang]["Logging out"] }}'
66
+ await logout({type: ConnectorType.STORAGE, connectorId: this.lastConnector.connectorId})
67
+ this.loggedIn = false
68
+ this.user = null
69
+ this.websites = []
70
+ this.loading = false
71
+ this.message = ''
72
+ this.error = false
73
+ } catch (error) {
74
+ console.error(error)
75
+ this.error = error
76
+ this.message = error.message
77
+ this.loading = false
78
+ }
79
+ },
41
80
  },
42
81
  };
43
82
 
@@ -30,6 +30,7 @@ window.addEventListener('load', function() {
30
30
  storage: null,
31
31
  user: null,
32
32
  showMenu: false,
33
+ empty: false,
33
34
  }
34
35
  },
35
36
  mounted() {
@@ -46,6 +47,7 @@ window.addEventListener('load', function() {
46
47
  this.user = user
47
48
  this.loggedIn = true
48
49
  this.websites = await websiteList({connectorId: this.user.storage.connectorId})
50
+ this.empty = this.websites.length === 0
49
51
  this.loading = false
50
52
  } else {
51
53
  this.openLogin()
@@ -53,11 +55,12 @@ window.addEventListener('load', function() {
53
55
  } catch (error) {
54
56
  console.error(error)
55
57
  this.loading = false
56
- if(error.code === 401) {
58
+ if(error.code === 401 || error.httpStatusCode === 401) {
57
59
  this.loggedIn = false
58
60
  this.openLogin()
59
61
  } else {
60
- this.error = error
62
+ this.error = `{{ api-translations[lang]["Failed to start dashboard"] }} - ${error.message}`
63
+ this.message = ''
61
64
  }
62
65
  }
63
66
  },
@@ -79,12 +82,13 @@ window.addEventListener('load', function() {
79
82
  type: ConnectorType.STORAGE,
80
83
  connectorId: this.user.storage.connectorId,
81
84
  })
85
+ window.location.reload()
82
86
  },
83
87
 
84
88
  async createWebsite() {
85
- if (!this.newWebsiteName) throw new Error('{{ api-translations[lang]["You need to provide a website name"] }}')
86
- this.loading = true
87
89
  try {
90
+ if (!this.newWebsiteName) throw new Error('{{ api-translations[lang]["You need to provide a website name"] }}')
91
+ this.loading = true
88
92
  const websiteId = this.newWebsiteName.replace(/[/\\?%*:|"<>]/g, '_')
89
93
  const result = await websiteCreate({
90
94
  websiteId,
@@ -95,15 +99,18 @@ window.addEventListener('load', function() {
95
99
  connectorId: this.user.storage.connectorId
96
100
  })
97
101
  this.message = '{{ api-translations[lang]["Website created successfully"] }}'
102
+ this.error = ''
98
103
  this.newWebsiteName = ''
99
104
  this.showCreationForm = false;
100
105
  this.websites = await websiteList({connectorId: this.user.storage.connectorId})
106
+ this.empty = this.websites.length === 0
101
107
  this.loading = false
102
108
  return result
103
109
  } catch (error) {
104
110
  this.loading = false
105
111
  console.error(error)
106
- this.error = '{{ api-translations[lang]["Failed to create website"] }}'
112
+ this.error = `{{ api-translations[lang]["Failed to create website"] }} - ${error.message}`
113
+ this.message = ''
107
114
  }
108
115
  },
109
116
 
@@ -114,12 +121,15 @@ window.addEventListener('load', function() {
114
121
  try {
115
122
  const result = await websiteDelete({websiteId, connectorId: this.user.storage.connectorId})
116
123
  this.message = '{{ api-translations[lang]["Website deleted successfully"] }}'
124
+ this.error = ''
117
125
  this.websites = await websiteList({connectorId: this.user.storage.connectorId})
126
+ this.empty = this.websites.length === 0
118
127
  this.loading = false
119
128
  return result
120
129
  } catch (error) {
121
130
  this.loading = false
122
- this.error = '{{ api-translations[lang]["Failed to delete website"] }}'
131
+ this.error = `{{ api-translations[lang]["Failed to delete website"] }} - ${error.message}`
132
+ this.message = ''
123
133
  }
124
134
  },
125
135
 
@@ -131,12 +141,15 @@ window.addEventListener('load', function() {
131
141
  try {
132
142
  const result = await websiteMetaWrite({websiteId, connectorId: this.user.storage.connectorId, data: { name }})
133
143
  this.message = '{{ api-translations[lang]["Website renamed successfully"] }}'
144
+ this.error = ''
134
145
  this.websites = await websiteList({connectorId: this.user.storage.connectorId})
146
+ this.empty = this.websites.length === 0
135
147
  this.loading = false
136
148
  return result
137
149
  } catch (error) {
138
150
  this.loading = false
139
- this.error = '{{ api-translations[lang]["Failed to delete website"] }}'
151
+ this.error = `{{ api-translations[lang]["Failed to rename website"] }} - ${error.message}`
152
+ this.message = ''
140
153
  }
141
154
  },
142
155
  },
@@ -46,29 +46,90 @@ a:hover { text-decoration: underline; }
46
46
  </head>
47
47
  <body
48
48
  id="i2hcfw"
49
- class=" app"
49
+ class="body app"
50
50
 
51
51
 
52
- ><div
52
+ ><HEADER
53
+
54
+ class="header padding-normal "
55
+
56
+
57
+ ><A
58
+ href="/"
59
+
60
+
61
+
62
+ ><img
63
+ src="/assets/silex-icon-2018@200px.png" href=""
64
+ class="nav__logo "
65
+
66
+
67
+ ></img></A><NAV
68
+ id="in5jeq"
69
+ class="nav "
70
+
71
+
72
+ >{% for item in nav %}<A
73
+ href="{{ item.url }}" id="i0g3ac"
74
+ class="nav__item {% if forloop.index == 1 %}active{% endif %}"
75
+ target="{{ item.target }}"
76
+
77
+ >{{ item.label }}</A>{% endfor %}</NAV><div
78
+
79
+ class="lang h-space "
80
+
81
+
82
+ >{% assign links = languages %}
83
+ {%- for link in links %}<A
84
+ href="/{{ link.code }}"
85
+ class="lang__item nav__item {% if link.code == lang %}active{% endif %}"
86
+ hreflang="{{link.code}}"
87
+
88
+ >{{ link.code }}</A>{% endfor %}</div></HEADER><A
89
+ id="ixzhcr" href="/"
90
+ class="button button-bar__item--secondary "
91
+
92
+
93
+ >{{ api-translations[lang]["Back to home"] }}</A><div
53
94
  id="imgx81"
54
95
 
55
96
 
56
97
 
57
- ><div
58
- id="in62y2"
98
+ ><H1
99
+ id="ighycb"
100
+ class="title "
59
101
 
60
102
 
103
+ >{{ api-translations[lang]["Welcome to Silex"] }}</H1><div
104
+ id="it2175"
105
+ class="subtitle "
61
106
 
62
- ><div
63
- id="isqe61"
64
107
 
65
- v-if="!loading" v-for="(connector, index) in connectors" :key="index"
108
+ >{{ api-translations[lang]["Please login to continue"] }}</div><div
109
+ id="in62y2"
110
+ class="button-bar "
111
+
112
+
113
+ ><A
114
+ id="isqe61" href="https://"
115
+ class="h-space button-bar__item--main button-bar_item button big-button "
116
+ v-if="!loading" v-for="(connector, index) in connectors" :key="index" :style="{ backgroundColor: connector.background, color: connector.color }" @click="openLogin(connector)"
66
117
 
67
118
  ><div
68
119
  id="i87asw"
69
120
 
121
+ v-text="connector.displayName"
122
+
123
+ >Insert your text here</div></A></div><div
124
+ id="i9msnk"
125
+
126
+ v-if="error" v-html="message"
70
127
 
128
+ >Insert your text here</div><div
129
+ id="i6akll"
130
+ class="button button--tertiary "
131
+ v-if="error" @click="logout()"
71
132
 
72
- >Insert your text here</div></div></div></div></body>
133
+ >{{ api-translations[lang]["Logout"] }}</div></div></body>
73
134
  </html>
74
135
 
@@ -88,7 +88,7 @@ a:hover { text-decoration: underline; }
88
88
  >{{ link.code }}</A>{% endfor %}</div><div
89
89
  id="i24ew"
90
90
  class="user__wrapper "
91
- v-if="user" @NOmouseover="showMenu = true" @NOmouseout="showMenu = false" @click="showMenu = !showMenu"
91
+ v-if="user && !user.storage.disableLogout" @NOmouseover="showMenu = true" @NOmouseout="showMenu = false" @click="showMenu = !showMenu"
92
92
 
93
93
  ><div
94
94
  id="i5xsbd"
@@ -116,16 +116,31 @@ a:hover { text-decoration: underline; }
116
116
 
117
117
 
118
118
  ><H1
119
- id="itp1f"
120
-
121
119
 
120
+ class="title "
121
+ v-if="!empty"
122
122
 
123
123
  >{{ title2 }}</H1><div
124
124
  id="iyex8"
125
- class="subtitle color--light "
125
+ class="subtitle "
126
+ v-if="!empty"
127
+
128
+ >{{ subtitle }}</div><SECTION
129
+ id="iqmx38"
130
+
131
+ v-if="empty"
132
+
133
+ ><H1
134
+
135
+ class="title "
136
+
137
+
138
+ >{{ title2-empty }}</H1><DIV
126
139
 
140
+ class="subtitle "
127
141
 
128
- >{{ subtitle }}</div><div
142
+
143
+ >{{ subtitle-empty }}</DIV></SECTION><div
129
144
  id="ickx4"
130
145
  class="button-bar margin-20 "
131
146
 
@@ -198,7 +213,7 @@ a:hover { text-decoration: underline; }
198
213
  >{{ add-cancel }}</button></div></form></div><div
199
214
  id="if80m"
200
215
 
201
-
216
+ v-if="!empty"
202
217
 
203
218
  ><SECTION
204
219
  id="idgvg"
@@ -315,31 +330,6 @@ a:hover { text-decoration: underline; }
315
330
  class="button-bar_item skeleton skeleton-button "
316
331
 
317
332
 
318
- >Edit</div></SECTION><SECTION
319
- id="iqmx38"
320
- class="button-bar button-bar--full-width bg-white rounded loading__item skeleton-anim skeleton-wrapper "
321
- v-if="loading"
322
-
323
- ><H3
324
-
325
- class="button-bar_item button-bar__item--main skeleton-text skeleton "
326
-
327
-
328
- >My first websiteMy first websiteMy first websiteMy first</H3><P
329
-
330
- class="button-bar_item button-bar__item--secondary skeleton-text skeleton "
331
-
332
-
333
- >Updated 1h ago by lexoyo</P><P
334
-
335
- class="button-bar_item button-bar__item--secondary skeleton-text skeleton "
336
-
337
-
338
- >Created 2023-02-16 by lexoyo</P><div
339
- id="ie83jl"
340
- class="button-bar_item skeleton skeleton-button "
341
-
342
-
343
333
  >Edit</div></SECTION></div><div
344
334
  id="i7ej6j"
345
335
  class="box horizontal "