Skip to content

Commit

Permalink
Add extension info
Browse files Browse the repository at this point in the history
  • Loading branch information
javalikescript committed Jan 12, 2025
1 parent efa0abf commit 04f85aa
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
19 changes: 19 additions & 0 deletions extensions/web-base/www/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
<button v-if="schema" v-on:click="onSave()" title="Save"><i class="fas fa-save"></i></button>
<button v-on:click="onReload" title="Reload"><i class="fas fa-redo"></i></button>
<button v-on:click="onRefreshThings" title="Refresh Things"><i class="fas fa-recycle"></i></button>
<button v-on:click="app.toPage('extension-info', extensionId)"><i class="fas fa-info"></i></button>
</template>
<article class="content">
<section>
Expand All @@ -217,6 +218,21 @@
</section>
</article>
</app-page>
<app-page id="extension-info" title="Extension Info">
<template slot="bar-right">
<button v-on:click="app.back()" title="Close"><i class="fa fa-window-close"></i></button>
</template>
<page-article>
<section>
<p>{{ info.name }}</p>
<p>{{ info.description }}</p>
<p>Version: {{ info.version }}</p>
</section>
<hr v-if="readme"/>
<div v-if="readme" v-html="readme">
</div>
</page-article>
</app-page>
<app-page id="addExtensions" title="Add Extensions">
<article class="cards">
<div class="card" v-for="extension in extensions" v-if="! extension.active">
Expand All @@ -231,6 +247,9 @@
</article>
</app-page>
<app-page id="addExtension" title="Add Extension">
<template slot="bar-right">
<button v-on:click="app.toPage('extension-info', extensionId)"><i class="fas fa-info"></i></button>
</template>
<article class="content">
<section>
<p>{{ extension.info.name }}</p>
Expand Down
20 changes: 20 additions & 0 deletions extensions/web-base/www/app/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,26 @@ new Vue({
}
});

new Vue({
el: '#extension-info',
data: {
info: {},
readme: ''
},
methods: {
onShow: function(extensionId) {
this.readme = '';
this.info = {};
fetch('/engine/extensions/' + extensionId + '/info').then(assertIsOk).then(getJson).then(function(info) {
this.info = info;
return fetch('/engine/extensions/' + extensionId + '/readme');
}.bind(this)).then(rejectIfNotOk).then(getResponseText).then(function(content) {
this.readme = content;
}.bind(this));
}
}
});

new Vue({
el: '#addExtensions',
data: {
Expand Down
4 changes: 4 additions & 0 deletions lha/Extension.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ return require('jls.lang.class').create(require('jls.util.EventPublisher'), func
return self.manifest.version or '1.0'
end

function extension:readme()
return self.manifest.readme or 'readme.md'
end

function extension:isActive()
return self.loaded and self.configuration.active
end
Expand Down
30 changes: 30 additions & 0 deletions lha/restEngine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local Logger = rootLogger:getClass()
local logger = rootLogger:get(...)
local system = require('jls.lang.system')
local event = require('jls.lang.event')
local loader = require('jls.lang.loader')
local File = require('jls.io.File')
local HTTP_CONST = require('jls.net.http.HttpMessage').CONST
local RestHttpHandler = require('jls.net.http.handler.RestHttpHandler')
Expand All @@ -13,6 +14,8 @@ local Map = require('jls.util.Map')
local ZipFile = require('jls.util.zip.ZipFile')
local Promise = require('jls.lang.Promise')

local md = loader.tryRequire('md')

local utils = require('lha.utils')

local engineSchema = utils.requireJson('lha.schema').properties.config.properties.engine
Expand Down Expand Up @@ -124,6 +127,33 @@ local REST_EXTENSIONS = {
manifest = function(exchange)
return exchange.attributes.extension:getManifest()
end,
['readme(extension)'] = function(exchange, extension)
local readme = File:new(extension:getDir(), extension:readme())
if not readme:isFile() then
HttpExchange.notFound(exchange)
return false
end
local readmeExt = string.lower(readme:getExtension())
local content = readme:readAll()
if readmeExt == 'md' then
if md then
content = md.render(content)
else
content = '<pre>'..content..'</pre>'
end
elseif readmeExt == 'txt' then
content = '<pre>'..content..'</pre>'
elseif not (readmeExt == 'html' or readmeExt == 'htm') then
HttpExchange.notFound(exchange)
return false
end
local response = exchange:getResponse()
response:setStatusCode(HTTP_CONST.HTTP_OK, 'OK')
response:setContentType('text/html')
response:setContentLength(#content)
response:setBody(content)
return false
end,
['poll(extension)?method=POST'] = function(exchange, extension)
if extension:isActive() then
extension:publishEvent('poll')
Expand Down
4 changes: 4 additions & 0 deletions lha/schema-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"title": "The description of the extension",
"type": "string"
},
"readme": {
"title": "The file documenting the extension",
"type": "string"
},
"name": {
"title": "The name of the extension",
"type": "string"
Expand Down

0 comments on commit 04f85aa

Please sign in to comment.