Skip to content

Commit

Permalink
Merge branch 'master' into GitHub_Actions_NuGet
Browse files Browse the repository at this point in the history
  • Loading branch information
Saibamen committed May 13, 2022
2 parents ad8a21c + ee5e7ab commit 03bf32a
Show file tree
Hide file tree
Showing 17 changed files with 1,059 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/publish-weblibs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish WebLibs

on: workflow_dispatch

jobs:
build-and-publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
working-directory: WebLibs
- run: npm publish
working-directory: WebLibs
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ packages
*.vspscc
*.user
bin/
obj/
obj/

node_modules/
1 change: 1 addition & 0 deletions WebLibs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WebLibs for Gandalan JS/TS/Svelte projects
8 changes: 8 additions & 0 deletions WebLibs/api/AuthStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { get, writable } from "svelte/store";

export const APP_TOKEN = "66B70E0B-F7C4-4829-B12A-18AD309E3970";
export const AuthToken = writable(localStorage.getItem("AuthToken"));
export const MandantGuid = writable(localStorage.getItem("MandantGuid"));
export const ApiBaseUrl = writable(localStorage.getItem("ApiBaseUrl") || "https://api.dev.idas-cloudservices.net/api");
export const SiteBaseUrl = writable(window.location.protocol + "//" + window.location.host);
export const SSOAuthUrl = writable(get(ApiBaseUrl).replace("/api", "") + "/SSO?a=" + APP_TOKEN + "&r=%target%?t=%token%%26m=%mandant%");
121 changes: 121 additions & 0 deletions WebLibs/api/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import axios from 'axios';
import { AuthToken, ApiBaseUrl } from "./AuthStore";
import { get } from 'svelte/store';

export class API
{
lastError = '';
token = "";
baseurl = "";

constructor()
{
this.lastError = "";
this.baseurl = get(ApiBaseUrl);
this.token = get(AuthToken);
console.log("Base: " + this.baseurl + " Token: " + this.token);

if (this.token) {
axios.defaults.headers.common['X-Gdl-AuthToken'] = this.token;
}
}

async get(uri)
{
try {
console.log("GET " + this.baseurl + uri);
const response = await axios.get(this.baseurl + uri);
this.lastError = '';
return response.data;
}
catch (error) {
this.checkError(error);
}
}

async getFile(uri)
{
try {
const response = await axios.get(this.baseurl + uri, { responseType: 'blob' });
console.log(response);

let fileName = "1000.pdf";
if (response.headers["content-disposition"]) {
fileName = response.headers["content-disposition"].split(';')[1];
fileName = fileName.replace("filename=", "").trim();
}

this.lastError = '';
return { data: response.data, filename: fileName, contentType: "application/pdf" };
}
catch (error) {
this.checkError(error);
}
}

async getRaw(uri)
{
let response = {};
try {
response = await axios.get(this.baseurl + uri, { withCredentials: true })
console.log(response);
this.lastError = '';
}
catch (error) {
this.checkError(error);
}
return response;
}

async post(uri, formData)
{
try {
const response = await axios.post(this.baseurl + uri, formData, { withCredentials: true });
//console.log(JSON.stringify(response));
this.lastError = '';
return response;
}
catch (error) {
this.checkError(error);
}
}

async put(uri, formData)
{
try {
console.log(`PUT to ${this.baseurl}${uri}`);
const response = await axios.put(this.baseurl + uri, formData, { withCredentials: true });
this.lastError = '';
return response;
}
catch (error) {
this.checkError(error);
}
}

async delete(uri)
{
try
{
console.log(`DELETE to ${this.baseurl}${uri}`);
const response = await axios.delete(this.baseurl + uri, { withCredentials: true });
this.lastError = '';
return response;
}
catch (error) {
this.checkError(error);
}
}

checkError(error)
{
let status = error && error.response ? error.response.status : -1;
let message = error ? error.message : "?";
console.log("API Error " + status + ": " + message);
this.lastError = message;
if (status === 401 || status === 403) {
AuthToken.set(null);
localStorage.setItem("AuthToken", null);
}
}
}
12 changes: 12 additions & 0 deletions WebLibs/api/mandantenApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { API } from './api';
import { AuthToken } from "./AuthStore";
//import mandanten from '../data/mandanten.json';

export function getAll()
{
//return mandanten;
if (AuthToken)
return new API().get('/Mandanten');
else
return [];
}
46 changes: 46 additions & 0 deletions WebLibs/api/nachrichtenApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { API } from './api';
import { get } from 'svelte/store'
import { MandantGuid } from "./AuthStore";

const niceContextNames = new Map();
niceContextNames.set("position", "Positionserfassung");
niceContextNames.set("start", "Programmstart");

export async function getAll()
{
let api = getNewAPI();
let result = await api.get('/NachrichtenKonfig?besitzerMandantGuid=' + get(MandantGuid));
result = result || [];
result.forEach(n => {
n.anzeigeText = n.nachricht && n.nachricht.length > 30 ? n.nachricht.substr(0,30) + "..." : n.nachricht;
if (n.context && niceContextNames.has(n.context))
{
n.anzeigeText += " (Anzeige bei " + niceContextNames.get(n.context) + ")";
}
});
return result;
}

export async function addNachricht(nachricht)
{
nachricht.besitzerMandantGuid = get(MandantGuid);
if (!nachricht.gueltigAb) nachricht.gueltigAb = null;
if (!nachricht.gueltigBis) nachricht.gueltigBis = null;

let api = getNewAPI();
console.log(nachricht);
return await api.post('/NachrichtenKonfig', nachricht);
}

export async function removeNachricht(nachricht)
{
let api = getNewAPI();
return await api.delete('/NachrichtenKonfig?nachrichtGuid=' + nachricht.nachrichtGuid);
}

function getNewAPI()
{
let api = new API();
api.baseurl = "";
return api;
}
12 changes: 12 additions & 0 deletions WebLibs/components/AddButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
import { Button } from 'svelte-chota';
import { mdiMessageAlert } from '@mdi/js'
export let Handler;
export let disabled;
export let title;
</script>

<Button primary outline title={title} on:click={Handler} icon={mdiMessageAlert} {disabled}>
{title}
</Button>
72 changes: 72 additions & 0 deletions WebLibs/components/DataGrid.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
import { Icon } from 'svelte-chota';
export let items = [];
export let selectedItem = {};
export let standardItem;
export let displayProperty = "";
export let header = "Überschrift";
export let key = "Guid";
export let marker = null;
export let markerField = "";
function setCurrent(item)
{
selectedItem = item;
console.log(item);
dispatch("selectedItemChanged", item);
}
</script>

<div class="datagrid">
<div class="dgheader">
{header}
</div>
<div>
{#if standardItem}
<div class="dgrow" on:click={setCurrent(standardItem)} class:selected="{selectedItem[key] === standardItem[key]}">{standardItem[displayProperty]}</div>
{/if}
{#each items as d}
<div class="dgrow" on:click={setCurrent(d)} class:selected="{selectedItem[key] === d[key]}">
{d[displayProperty]}
{#if marker && markerField && d[markerField] === true}
<Icon src={marker} />
{/if}
</div>
{/each}
</div>
</div>

<style>
.datagrid {
border: 1px solid var(--color-darkGrey);
background-color: var(--color-grey);
display: flex;
flex-direction: column;
justify-content: flex-start;
align-content: flex-start;
cursor: pointer;
}
.dgheader {
background-color: var(--color-grey);
padding: 4px 4px 4px 8px;
flex: 1;
}
.dgrow {
margin-left: 8px;
border-bottom: 1px solid var(--color-darkGrey);
background-color: #fff;
padding: 4px;
flex: 1;
}
.selected {
background-color: var(--color-selected);
color: var(--color-selected-text);
}
</style>
Loading

0 comments on commit 03bf32a

Please sign in to comment.