Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesread committed Jan 21, 2024
1 parent 86a6fe4 commit de3ec4f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
22 changes: 17 additions & 5 deletions src/js/firmware/middleware.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { generalError } from './util.js'

export function ajaxRequest (params) {
let fetchParams = {
'credentials': 'include'
}

if (typeof (params.error) !== 'function') {
params.error = generalError
}
Expand All @@ -18,14 +22,22 @@ export function ajaxRequest (params) {

const url = new URL(window.location.protocol + '//' + window.location.hostname + ":8080/api/" + params.url)

if (typeof (params.method) !== 'undefined') {
fetchParams.method = params.method
} else {
fetchParams.method == 'GET'
}

if (typeof (params.data) !== 'undefined') {
Object.keys(params.data).forEach(key => url.searchParams.append(key, params.data[key]))
if (fetchParams.method == 'GET') {
Object.keys(params.data).forEach(key => url.searchParams.append(key, params.data[key]))
} else {
fetchParams.body = JSON.stringify(params.data)
fetchParams.method = 'POST'
}
}

window.fetch(url, {
method: 'GET',
credentials: 'include'
})
window.fetch(url, fetchParams)
.then(resp => {
if (!resp.ok) {
Promise.reject(resp)
Expand Down
5 changes: 1 addition & 4 deletions src/js/modules/DatabaseRemoteServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ import { ajaxRequest } from '../firmware/middleware.js'
export class DatabaseRemoteServer {
getTasks (theListId) {
ajaxRequest({
url: 'Task/List',
url: 'Task/List/' + theListId,
success: (jsonTasks) => {
window.dbal.local.addTasksFromServer(jsonTasks)
},
data: {
listId: theListId
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions src/js/modules/UiManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ export class UiManager {
}
}

onBootloaderSuccess (res) {
onBootloaderSuccess (init) {
document.querySelector('#initMessages').remove()

if (res.wallpaper !== null) {
const img = 'url(/wallpapers/' + res.Wallpaper + ')'
if (init.wallpaper !== null) {
const img = 'url(/wallpapers/' + init.wallpaper + ')'
document.body.style.backgroundImage = img
}

window.loginForm = document.createElement('login-form')
window.loginForm.create()

if (res.username !== null) {
if (init.username !== null) {
this.loginSuccess()
} else {
window.loginForm.show()
Expand Down
3 changes: 2 additions & 1 deletion src/js/modules/webcomponents/SidePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export class SidePanel extends HTMLElement {
}

ajaxRequest({
url: 'CreateList',
url: 'List/Create',
method: 'POST',
data: {
title: title
},
Expand Down

0 comments on commit de3ec4f

Please sign in to comment.