Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make webui work with non-root context path #1305

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bundles/org.openhab.ui.basic/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
.pipe(gulp.dest("./src/main/resources/web"));
});

gulp.task("tile", function() {
return gulp.src("web-src/tile.png")
.pipe(gulp.dest("./src/main/resources/web"));
});

gulp.task("eslint", function() {
return gulp.src(sources.js)
.pipe(eslint({
Expand All @@ -48,5 +53,5 @@
.pipe(gulp.dest("./src/main/resources/web"));
});

gulp.task("default", gulp.parallel("css", "copyFontLibs", gulp.series("eslint", "js")));
gulp.task("default", gulp.parallel("css", "tile", "copyFontLibs", gulp.series("eslint", "js")));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

function getIconUrl(iconset, icon, state) {
if (iconset === 'custom-icon') {
return '/icon/' + icon + '?format=svg' + ((state) ? '&state=' + state : '');
return '../icon/' + icon + '?format=svg' + ((state) ? '&state=' + state : '');
} else if (iconset === 'custom-url') {
return icon;
}
Expand All @@ -34,7 +34,7 @@
if (set.type === 'builtin') {
return 'assets/icons/' + set.id + '/' + icon + '.svg';
} else {
return '/icon/' + icon + '?format=svg' + ((state) ? '&state=' + state : '');
return '../icon/' + icon + '?format=svg' + ((state) ? '&state=' + state : '');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

$http({
method: 'GET',
url: '/rest/services/' + SERVICE_NAME + '/config',
url: '../rest/services/' + SERVICE_NAME + '/config',
headers: headers
}).then(function (resp) {
console.log('openHAB 2 service configuration loaded');
Expand Down Expand Up @@ -77,7 +77,7 @@
OH3StorageService.getAccessToken().then(function (accessToken) {
$http({
method: 'PUT',
url: '/rest/services/' + SERVICE_NAME + '/config',
url: '../rest/services/' + SERVICE_NAME + '/config',
data: OH2ServiceConfiguration,
headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + accessToken }
}).then (function (resp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
} else {
$http({
method: 'POST',
url: '/rest/auth/token',
url: '../rest/auth/token',
data: 'grant_type=refresh_token&client_id=' + window.location.origin +
'&redirect_uri=' + window.location.origin + '&refresh_token=' + refreshToken,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
Expand All @@ -49,7 +49,7 @@
if (!refreshToken) {
$rootScope.lockEditing = true;
}
$http.get('/rest/ui/components/habpanel:panelconfig').then(function (data) {
$http.get('../rest/ui/components/habpanel:panelconfig').then(function (data) {
console.log('Panel configurations loaded');
$rootScope.panelsRegistry = transformUIComponentsToPanelRegistry(data.data);
deferred.resolve($rootScope.panelsRegistry);
Expand Down Expand Up @@ -77,11 +77,11 @@
headers['Authorization'] = 'Bearer ' + accessToken
}

$http.get('/rest/ui/components/habpanel:panelconfig/' + getCurrentPanelConfig()).then(function (data) {
$http.get('../rest/ui/components/habpanel:panelconfig/' + getCurrentPanelConfig()).then(function (data) {
// update
$http({
method: 'PUT',
url: '/rest/ui/components/habpanel:panelconfig/' + getCurrentPanelConfig(),
url: '../rest/ui/components/habpanel:panelconfig/' + getCurrentPanelConfig(),
data: transformPanelConfigurationToUIComponent(getCurrentPanelConfig(), panelConfiguration),
headers: headers
}).then (function (resp) {
Expand All @@ -95,7 +95,7 @@
// assume the error is 404?
$http({
method: 'POST',
url: '/rest/ui/components/habpanel:panelconfig',
url: '../rest/ui/components/habpanel:panelconfig',
data: transformPanelConfigurationToUIComponent(getCurrentPanelConfig(), panelConfiguration),
headers: headers
}).then (function (resp) {
Expand Down Expand Up @@ -127,7 +127,7 @@

$http({
method: 'DELETE',
url: '/rest/ui/components/habpanel:panelconfig/' + id,
url: '../rest/ui/components/habpanel:panelconfig/' + id,
headers: headers
}).then (function (resp) {
console.log('Panel configuration deleted');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$timeout($rootScope.$emit('openhab-update'));
}

$http.get('/rest/items')
$http.get('../rest/items')
.then(function (data) {
if (angular.isArray(data.data)) {
console.log("Loaded " + data.data.length + " openHAB items");
Expand Down Expand Up @@ -71,7 +71,7 @@
function sendCmd(item, cmd) {
$http({
method : 'POST',
url : '/rest/items/' + item,
url : '../rest/items/' + item,
data : cmd,
headers: { 'Content-Type': 'text/plain' }
}).then(function (data) {
Expand All @@ -92,7 +92,7 @@
if (locale) {
deferred.resolve(locale);
} else {
$http.get('/rest/')
$http.get('../rest/')
.then(function (response) {
if (!response.data.locale) {
if (navigator && navigator.languages) {
Expand Down Expand Up @@ -145,7 +145,7 @@
function sendVoice(text) {
$http({
method : 'POST',
url : '/rest/voice/interpreters',
url : '../rest/voice/interpreters',
data : text,
headers: { 'Content-Type': 'text/plain' }
}).then(function (data) {
Expand All @@ -161,7 +161,7 @@

function registerEventSource() {
if (typeof(EventSource) !== "undefined") {
var source = new EventSource('/rest/events?topics=openhab/items/*/statechanged,openhab/items/*/*/statechanged,openhab/webaudio/playurl');
var source = new EventSource('../rest/events?topics=openhab/items/*/statechanged,openhab/items/*/*/statechanged,openhab/webaudio/playurl');
liveUpdatesEnabled = true;

source.onmessage = function (event) {
Expand Down Expand Up @@ -192,7 +192,7 @@
}
} else {
// fetch the new transformed state
$http.get('/rest/items/' + item.name).then(function (response) {
$http.get('../rest/items/' + item.name).then(function (response) {
if (response.data && response.data.transformedState) {
item.transformedState = response.data.transformedState;
$rootScope.$emit('openhab-update', item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
vm.progressMax = 1;
vm.progressCurrent = 1;

$http.get('/rest/habpanel/gallery/community/widgets')
$http.get('../rest/habpanel/gallery/community/widgets')
.then(function (resp) {
vm.busy = false;
if (resp.data) {
Expand Down Expand Up @@ -52,7 +52,7 @@
vm.progressMax = 1;
vm.progressCurrent = 1;

$http.get('/rest/habpanel/gallery/community/widgets/' + id)
$http.get('../rest/habpanel/gallery/community/widgets/' + id)
.then(function (resp) {
vm.galleryItemDetails = resp.data;
if (vm.galleryItemDetails.authorAvatarUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@

vm.rawdata = [];
for (var i = 0; i < vm.widget.series.length; i++) {
vm.rawdata[i] = $http.get('/rest/persistence/items/' + vm.widget.series[i].item + "?starttime=" + startDate.toISOString() + (vm.widget.service ? '&serviceId=' + vm.widget.service : ''));
vm.rawdata[i] = $http.get('../rest/persistence/items/' + vm.widget.series[i].item + "?starttime=" + startDate.toISOString() + (vm.widget.service ? '&serviceId=' + vm.widget.service : ''));
}

$q.all(vm.rawdata).then(function (values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@

vm.rawdata = [];
for (var i = 0; i < vm.widget.series.length; i++) {
vm.rawdata[i] = $http.get('/rest/persistence/items/' + vm.widget.series[i].item + "?boundary=true&starttime=" + startDate.toISOString() + (vm.widget.service ? '&serviceId=' + vm.widget.service : ''));
vm.rawdata[i] = $http.get('../rest/persistence/items/' + vm.widget.series[i].item + "?boundary=true&starttime=" + startDate.toISOString() + (vm.widget.service ? '&serviceId=' + vm.widget.service : ''));
}


Expand Down
3 changes: 2 additions & 1 deletion bundles/org.openhab.ui/web/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ module.exports = {
'ga': true, // Google Analytics
'cordova': true,
'__statics': true,
'process': true
'process': true,
'baseUrl': true
},

// add your custom rules here
Expand Down
6 changes: 3 additions & 3 deletions bundles/org.openhab.ui/web/build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ module.exports = {
new HtmlWebpackPlugin({
filename: './index.html',
template: './src/index.html',
inject: true,
inject: false,
minify: env === 'production' ? {
collapseWhitespace: true,
removeComments: true,
Expand All @@ -219,8 +219,8 @@ module.exports = {
}),
new CopyWebpackPlugin([
{
from: resolvePath('src/res'),
to: resolvePath(isCordova ? 'cordova/www/res' : 'www/res')
from: resolvePath('src/images'),
to: resolvePath(isCordova ? 'cordova/www/images' : 'www/images')
},
{
from: resolvePath('src/manifest.json'),
Expand Down
3 changes: 2 additions & 1 deletion bundles/org.openhab.ui/web/src/components/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ export default {
iosSwipeBack: !this.$device.ios || this.$device.cordova,
auroraSwipeBack: !this.$device.ios || this.$device.cordova,
pushState: true, // !this.$device.cordova
pushStateRoot: baseUrl,
pushStateSeparator: ''
},
// Enable panel left visibility breakpoint
Expand Down Expand Up @@ -510,7 +511,7 @@ export default {
this.cleanSession().then(() => {
this.loggedIn = false
this.$f7.views.main.router.navigate('/', { animate: false, clearPreviousHistory: true })
window.location = window.location.origin
window.location = window.location.origin + baseUrl + '/'
if (this.$device.cordova) {
this.loginScreenOpened = true
}
Expand Down
8 changes: 4 additions & 4 deletions bundles/org.openhab.ui/web/src/components/auth-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default {

const payload = Utils.serializeObject({
'grant_type': 'authorization_code',
'client_id': window.location.origin,
'redirect_uri': window.location.origin,
'client_id': window.location.origin + baseUrl,
'redirect_uri': window.location.origin + baseUrl + '/',
'code': queryParams.code,
'code_verifier': codeVerifier
})
Expand Down Expand Up @@ -65,8 +65,8 @@ export default {
const refreshToken = this.getRefreshToken()
const payload = Utils.serializeObject({
'grant_type': 'refresh_token',
'client_id': window.location.origin,
'redirect_uri': window.location.origin,
'client_id': window.location.origin + baseUrl,
'redirect_uri': window.location.origin + baseUrl + '/',
'refresh_token': refreshToken
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export default {
updateIcon () {
if (!this.currentIcon) return
this.$oh.media.getIcon(this.currentIcon, this.iconFormat, this.currentState).then((url) => {
if (url !== this.iconUrl) {
this.iconUrl = url
if (baseUrl + url !== this.iconUrl) {
this.iconUrl = baseUrl + url
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions bundles/org.openhab.ui/web/src/css/icons.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
font-weight: 400;
src: local('Material Icons'),
local('MaterialIcons-Regular'),
url(../fonts/MaterialIcons-Regular.woff2) format('woff2'),
url(../fonts/MaterialIcons-Regular.woff) format('woff'),
url(../fonts/MaterialIcons-Regular.ttf) format('truetype');
url("../fonts/MaterialIcons-Regular.woff2") format('woff2'),
url("../fonts/MaterialIcons-Regular.woff") format('woff'),
url("../fonts/MaterialIcons-Regular.ttf") format('truetype');
}
.material-icons {
font-family: 'Material Icons';
Expand Down
21 changes: 16 additions & 5 deletions bundles/org.openhab.ui/web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@
<% if (process.env.TARGET === 'web') { %>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<link rel="apple-touch-icon" href="/res/icons/apple-touch-icon.png" type="image/png" sizes="180x180" crossorigin="use-credentials">
<link rel="icon" href="/res/icons/favicon.svg" type="image/svg+xml" sizes="any" crossorigin="use-credentials">
<link rel="icon" href="/res/icons/128x128.png" type="image/png" sizes="128x128" crossorigin="use-credentials">
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials">
<link rel="apple-touch-icon" href="images/icons/apple-touch-icon.png" type="image/png" sizes="180x180" crossorigin="use-credentials">
<link rel="icon" href="images/icons/favicon.svg" type="image/svg+xml" sizes="any" crossorigin="use-credentials">
<link rel="icon" href="images/icons/128x128.png" type="image/png" sizes="128x128" crossorigin="use-credentials">
<link rel="manifest" href="manifest.json" crossorigin="use-credentials">
<% } %>
<!-- built styles file will be auto injected -->
<script>
const baseUrl = document.cookie.match('(^|;)\\s*X-OPENHAB-BASEURL\\s*=\\s*([^;]+)')?.pop().replace(/\/$/, '') || '';

var base = document.createElement('base');
base.href = baseUrl + '/';
document.head.appendChild(base);
</script>
</head>
<body>
<div id="app"></div>
<% if (process.env.TARGET === 'cordova') { %>
<script src="cordova.js"></script>
<% } %>
<!-- built script files will be auto injected -->
<script>
let app = document.createElement('script');
app.setAttribute('src', baseUrl + "/js/app.js");
document.body.appendChild(app);
</script>
</body>
</html>
1 change: 1 addition & 0 deletions bundles/org.openhab.ui/web/src/js/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './public-path.js'
import './compatibility'

// Import Vue
Expand Down
16 changes: 8 additions & 8 deletions bundles/org.openhab.ui/web/src/js/openhab/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ Framework7.request.setup({

export default {
get (uri, data) {
return wrapPromise(Framework7.request.promise.json(uri, data))
return wrapPromise(Framework7.request.promise.json(baseUrl + uri, data))
},
getPlain (uri, data, contentType) {
return wrapPromise(Framework7.request.promise({
method: 'GET',
url: uri,
url: baseUrl + uri,
data,
processData: false,
contentType: contentType || 'text/plain'
}))
},
post (uri, data, dataType) {
return wrapPromise(Framework7.request.promise.postJSON(uri, data, dataType))
return wrapPromise(Framework7.request.promise.postJSON(baseUrl + uri, data, dataType))
},
postPlain (uri, data, dataType, contentType) {
return wrapPromise(Framework7.request.promise({
method: 'POST',
url: uri,
url: baseUrl + uri,
data,
processData: false,
contentType: contentType || 'text/plain',
Expand All @@ -55,7 +55,7 @@ export default {
put (uri, data) {
return wrapPromise(Framework7.request.promise({
method: 'PUT',
url: uri,
url: baseUrl + uri,
data: JSON.stringify(data),
processData: false,
// dataType: 'json',
Expand All @@ -65,7 +65,7 @@ export default {
putPlain (uri, data, dataType, contentType) {
return wrapPromise(Framework7.request.promise({
method: 'PUT',
url: uri,
url: baseUrl + uri,
data,
processData: false,
// dataType: 'json',
Expand All @@ -76,13 +76,13 @@ export default {
head (uri) {
return wrapPromise(Framework7.request.promise({
method: 'HEAD',
url: uri
url: baseUrl + uri
}))
},
delete (uri, data) {
return wrapPromise(Framework7.request.promise({
method: 'DELETE',
url: uri,
url: baseUrl + uri,
processData: false,
// dataType: 'json',
contentType: 'application/json'
Expand Down
Loading