Skip to content
Snippets Groups Projects
Commit 933214dc authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Remove organization-select

parent 05719454
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 981 deletions
/vendor/**
/dist/**
/*.js
\ No newline at end of file
{
"root": true,
"extends": "./../../eslint.common.json"
}
dist
node_modules
.idea
npm-debug.log
package-lock.json
node_modules
.idea
npm-debug.log
package-lock.json
index.html
node_modules/
/dist
/vendor
{
"bracketSpacing": false,
"singleQuote": true,
"tabWidth": 4,
"printWidth": 100,
"bracketSameLine": true,
"htmlWhitespaceSensitivity": "ignore",
"overrides": [
{
"files": "*.js",
"options": {
"semi": true
}
}
]
}
This diff is collapsed.
# Organization Select Web Component
You can install this component via npm:
```bash
npm i @dbp-toolkit/organization-select
```
## Usage
```html
<dbp-organization-select></dbp-organization-select>
<script type="module" src="node_modules/@dbp-toolkit/organization-select/dist/dbp-organization-select.js"></script>
```
Or directly via CDN:
```html
<dbp-organization-select></dbp-organization-select>
<script type="module" src="https://unpkg.com/@dbp-toolkit/organization-select@0.2.2/dist/dbp-organization-select.js"></script>
```
## Attributes
- `lang` (optional, default: `de`): set to `de` or `en` for German or English
- example `<dbp-organization-select lang="de"></dbp-organization-select>`
- `entry-point-url` (optional, default is the TU Graz entry point url): entry point url to access the api
- example `<dbp-organization-select entry-point-url="http://127.0.0.1:8000"></dbp-organization-select>`
- `value` (optional): api path of organization to preload the selector with
- example `<dbp-organization-select value="/base/people/testuser"></dbp-organization-select>`
- the `value` will also be set automatically when an organization is chosen in the selector
- `context` (optional): the context of the returned organizations
- example `<dbp-organization-select context="libray-manager"></dbp-organization-select>` returns all organizations
where the current user is library manager
- if no `context` is set all organizations are returned that are in a relation with the current user
- `data-object` (read-only): when an organization is selected the organization object will be set as json string
- example `<dbp-organization-select data-object="{"@id":"/organizations/1190-F2050","@type":"http://schema.org/Organization","identifier":"1190-F2050","name":"Institut für Stahlbau","url":"https://online.tugraz.at/tug_online/wborg.display?pOrgNr=1190","alternateName":"F2050"}"></dbp-organization-select>`
- `auth` object: you need to set that object property for the auth token
- example auth property: `{token: "THE_BEARER_TOKEN"}`
- note: most often this should be an attribute that is not set directly, but subscribed at a provider
## Local development
```bash
# get the source
git clone git@gitlab.tugraz.at:dbp/web-components/toolkit.git
cd toolkit/packages/organization-select
# install dependencies
yarn install
# constantly build dist/bundle.js and run a local web-server on port 8002
yarn run watch
# run tests
yarn test
# build local packages in dist directory
yarn run build
```
Jump to <http://localhost:8002> and you should get a Single Sign On login page.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script type="module" src="dbp-organization-select-demo.js"></script>
</head>
<body>
<dbp-organization-select-demo auth requested-login-status lang="de" entry-point-url="http://127.0.0.1:8000"></dbp-organization-select-demo>
</body>
</html>
module.exports = {
createOldCatalogs: false,
indentation: 4,
keepRemoved: false,
locales: ['en', 'de'],
output: 'src/i18n/$LOCALE/$NAMESPACE.json',
input: ['src/**/*.js'],
sort: true,
i18nextOptions: {compatibilityJSON: 'v3'},
};
module.exports = require('../../karma.common.conf.js');
{
"name": "@dbp-toolkit/organization-select",
"homepage": "https://gitlab.tugraz.at/dbp/web-components/toolkit/-/tree/master/packages/organization-select",
"version": "0.2.4",
"main": "src/index.js",
"license": "LGPL-2.1-or-later",
"repository": {
"type": "git",
"url": "https://gitlab.tugraz.at/dbp/web-components/toolkit.git",
"directory": "packages/organization-select"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
},
"devDependencies": {
"@esm-bundle/chai": "^4.2.0",
"@rollup/plugin-commonjs": "^21.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-url": "^6.0.0",
"eslint": "^8.0.0",
"eslint-plugin-jsdoc": "^39.0.0",
"i18next-parser": "^6.3.0",
"karma": "^6.0.0",
"karma-chrome-launcher": "^3.0.0",
"karma-firefox-launcher": "^2.1.0",
"karma-mocha": "^2.0.1",
"mocha": "^9.0.0",
"playwright-core": "^1.20.2",
"prettier": "^2.5.1",
"rollup": "^2.33.3",
"rollup-plugin-copy": "^3.1.0",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-serve": "^1.0.1",
"rollup-plugin-terser": "^7.0.2"
},
"dependencies": {
"@dbp-toolkit/auth": "^0.3.0",
"@dbp-toolkit/common": "^0.3.0",
"@open-wc/scoped-elements": "^2.1.0",
"jquery": "^3.4.1",
"lit": "^2.0.0",
"select2": "^4.0.10"
},
"scripts": {
"clean": "rm dist/*",
"format": "yarn run format:eslint && yarn run format:prettier",
"format:eslint": "eslint \"**/*.{js,ts}\" --fix",
"format:prettier": "prettier \"**/*.{js,json,ts}\" --write",
"build": "npm run build-local",
"build-local": "rollup -c",
"build-dev": "rollup -c --environment BUILD:development",
"build-prod": "rollup -c --environment BUILD:production",
"build-demo": "rollup -c --environment BUILD:demo",
"build-test": "rollup -c --environment BUILD:test",
"i18next": "i18next",
"watch": "npm run watch-local",
"watch-local": "rollup -c --watch",
"watch-dev": "rollup -c --watch --environment BUILD:development",
"test": "npm run build-test && karma start --singleRun",
"lint": "eslint ."
}
}
import glob from 'glob';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import {terser} from 'rollup-plugin-terser';
import json from '@rollup/plugin-json';
import serve from 'rollup-plugin-serve';
import url from '@rollup/plugin-url';
import del from 'rollup-plugin-delete';
import {getPackagePath, getDistPath} from '../../rollup.utils.js';
const build = typeof process.env.BUILD !== 'undefined' ? process.env.BUILD : 'local';
console.log('build: ' + build);
export default (async () => {
return {
input:
build != 'test'
? ['src/dbp-organization-select.js', 'src/dbp-organization-select-demo.js']
: glob.sync('test/**/*.js'),
output: {
dir: 'dist',
entryFileNames: '[name].js',
chunkFileNames: 'shared/[name].[hash].[format].js',
format: 'esm',
sourcemap: true,
},
plugins: [
del({
targets: 'dist/*',
}),
resolve(),
commonjs(),
url({
limit: 0,
include: [await getPackagePath('select2', '**/*.css')],
emitFiles: true,
fileName: 'shared/[name].[hash][extname]',
}),
json(),
build !== 'local' && build !== 'test' ? terser() : false,
copy({
targets: [
{src: 'assets/index.html', dest: 'dist'},
{
src: await getPackagePath('@dbp-toolkit/common', 'assets/icons/*.svg'),
dest: 'dist/' + (await getDistPath('@dbp-toolkit/common', 'icons')),
},
],
}),
process.env.ROLLUP_WATCH === 'true'
? serve({contentBase: 'dist', host: '127.0.0.1', port: 8002})
: false,
],
};
})();
import {createInstance} from './i18n.js';
import {css, html} from 'lit';
import {ScopedElementsMixin} from '@open-wc/scoped-elements';
import {OrganizationSelect} from './organization-select.js';
import {AuthKeycloak, LoginButton} from '@dbp-toolkit/auth';
import * as commonUtils from '@dbp-toolkit/common/utils';
import * as commonStyles from '@dbp-toolkit/common/styles';
import DBPLitElement from '@dbp-toolkit/common/dbp-lit-element';
export class OrganizationSelectDemo extends ScopedElementsMixin(DBPLitElement) {
constructor() {
super();
this._i18n = createInstance();
this.lang = this._i18n.language;
this.entryPointUrl = '';
this.noAuth = false;
}
static get scopedElements() {
return {
'dbp-auth-keycloak': AuthKeycloak,
'dbp-login-button': LoginButton,
'dbp-organization-select': OrganizationSelect,
};
}
static get properties() {
return {
...super.properties,
lang: {type: String},
entryPointUrl: {type: String, attribute: 'entry-point-url'},
noAuth: {type: Boolean, attribute: 'no-auth'},
};
}
update(changedProperties) {
if (changedProperties.has('lang')) {
this._i18n.changeLanguage(this.lang);
}
super.update(changedProperties);
}
static get styles() {
// language=css
return [
commonStyles.getThemeCSS(),
commonStyles.getGeneralCSS(),
css`
h1.title {
margin-bottom: 1em;
}
div.container {
margin-bottom: 1.5em;
}
`,
];
}
getAuthComponentHtml() {
return this.noAuth
? html`
<dbp-login-button subscribe="auth" lang="${this.lang}"></dbp-login-button>
`
: html`
<div class="container">
<dbp-auth-keycloak
subscribe="requested-login-status"
lang="${this.lang}"
entry-point-url="${this.entryPointUrl}"
silent-check-sso-redirect-uri="/dist/silent-check-sso.html"
url="https://auth-dev.tugraz.at/auth"
realm="tugraz-vpu"
client-id="auth-dev-mw-frontend-local"
try-login></dbp-auth-keycloak>
<dbp-login-button subscribe="auth" lang="${this.lang}"></dbp-login-button>
</div>
`;
}
render() {
return html`
<section class="section">
<div class="container">
<h1 class="title">Organization-Select-Demo</h1>
</div>
${this.getAuthComponentHtml()}
<div class="container">
<form>
<div class="field">
<label class="label">
All related organization of the current user
</label>
<div class="control">
<dbp-organization-select
id="organization-select-all"
subscribe="auth"
lang="${this.lang}"
entry-point-url="${this
.entryPointUrl}"></dbp-organization-select>
</div>
</div>
<div class="field">
<label class="label">
Organization where the current user is library-manager
</label>
<div class="control">
<dbp-organization-select
id="organization-select-library-manager"
subscribe="auth"
lang="${this.lang}"
entry-point-url="${this.entryPointUrl}"
context="library-manager"></dbp-organization-select>
</div>
</div>
</form>
</div>
</section>
`;
}
}
commonUtils.defineCustomElement('dbp-organization-select-demo', OrganizationSelectDemo);
import * as commonUtils from '@dbp-toolkit/common/utils';
import {OrganizationSelect} from './organization-select.js';
commonUtils.defineCustomElement('dbp-organization-select', OrganizationSelect);
import './dbp-organization-select-demo.js';
import {createInstance as _createInstance} from '@dbp-toolkit/common/i18next.js';
import de from './i18n/de/translation.json';
import en from './i18n/en/translation.json';
export function createInstance() {
return _createInstance({en: en, de: de}, 'de', 'en');
}
/**
* Content from https://github.com/select2/select2/blob/master/src/js/select2/i18n/de.js
*/
export default function () {
// German
return {
errorLoading: function () {
return 'Die Ergebnisse konnten nicht geladen werden.';
},
inputTooLong: function (args) {
var overChars = args.input.length - args.maximum;
return 'Bitte ' + overChars + ' Zeichen weniger eingeben';
},
inputTooShort: function (args) {
var remainingChars = args.minimum - args.input.length;
return 'Bitte ' + remainingChars + ' Zeichen mehr eingeben';
},
loadingMore: function () {
return 'Lade mehr Ergebnisse…';
},
maximumSelected: function (args) {
var message = 'Sie können nur ' + args.maximum + ' Eintr';
if (args.maximum === 1) {
message += 'ag';
} else {
message += 'äge';
}
message += ' auswählen';
return message;
},
noResults: function () {
return 'Keine Übereinstimmungen gefunden';
},
searching: function () {
return 'Suche…';
},
removeAllItems: function () {
return 'Auswahl aufheben';
},
};
}
{
"select-organization": {
"loading": "Wird geladen...",
"placeholder": "Bitte wählen Sie ein Institut aus"
}
}
/**
* Content from https://github.com/select2/select2/blob/master/src/js/select2/i18n/en.js
*/
export default function () {
// English
return {
errorLoading: function () {
return 'The results could not be loaded.';
},
inputTooLong: function (args) {
var overChars = args.input.length - args.maximum;
var message = 'Please delete ' + overChars + ' character';
if (overChars != 1) {
message += 's';
}
return message;
},
inputTooShort: function (args) {
var remainingChars = args.minimum - args.input.length;
var message = 'Please enter ' + remainingChars + ' or more characters';
return message;
},
loadingMore: function () {
return 'Loading more results…';
},
maximumSelected: function (args) {
var message = 'You can only select ' + args.maximum + ' item';
if (args.maximum != 1) {
message += 's';
}
return message;
},
noResults: function () {
return 'No results found';
},
searching: function () {
return 'Searching…';
},
removeAllItems: function () {
return 'Remove selection';
},
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment