Commit ac0bc27a authored by Yorrd's avatar Yorrd
Browse files

feat: better filter

parent a6f8d236
......@@ -23,6 +23,7 @@ import { repeat } from 'lit-html/directives/repeat';
@element('ccb-contents-admin')
export class CCBContentsAdmin extends AdornisDBView<Content> {
@rerender public filterForOwnEntities = new BehaviorSubject(false);
@rerender public filterForNoIntentField = new BehaviorSubject(false);
@rerender public chosenRechtsgebiet = new BehaviorSubject('');
@rerender public opened = new BehaviorSubject(-1);
......@@ -45,27 +46,20 @@ export class CCBContentsAdmin extends AdornisDBView<Content> {
});
}
public render({ fields, selectedFields, entities, sorting, filterForOwnEntities }: RenderProps<CCBContentsAdmin>) {
public render({
fields,
selectedFields,
entities,
sorting,
filterForOwnEntities,
filterForNoIntentField,
}: RenderProps<CCBContentsAdmin>) {
return html`
<a-box padding="${listenDevice.pipe(map(device => (device < BreakPoint.laptop ? '' : 'xxl')))}">
<a-stack size="md" padding="lg">
${this.searchBar()} ${this.addNewEntry(fields)}
<ccb-text
>Du hast
${this.entities.pipe(
startWith(of([])),
switchMap(ents => ents.pipe(map(ents => ents.length))),
)}
von insgesamt ${Content.count({}).whenReady} Einträgen erstellt. Der durchschnittliche Nutzer erstellt
${Content.count({}).whenReady.pipe(
switchMap(count =>
AdornisUser.count({}).whenReady.pipe(map(userCount => (count / userCount).toFixed(2))),
),
)}
Einträge.</ccb-text
>
${this.searchBar()}
<a-stack horizontal size="md">
${this.filterForOwn()} ${this.csvUploadButton()}
${this.filterForOwn()} ${this.filterForNoIntent()}
</a-stack>
</a-stack>
<a-stack size="">
......@@ -74,6 +68,7 @@ export class CCBContentsAdmin extends AdornisDBView<Content> {
map(([ents, user]) =>
ents
.filter(ent => !filterForOwnEntities || !user || user._id === ent.createdBy)
.filter(ent => !filterForNoIntentField || !ent.intent)
.sort(this.sortFunctionWithSortObject(sorting)),
),
),
......@@ -87,15 +82,22 @@ export class CCBContentsAdmin extends AdornisDBView<Content> {
protected searchBar() {
return html`
<a-stack size="md">
<mwc-textfield
class="${this.css({ width: '100%' })}"
label="Suche in selektierten Feldern"
icon="search"
@input="${e => {
const val = e.currentTarget.value;
this.applySearch(val);
}}"
></mwc-textfield>
<a-inline size="md">
<mwc-textfield
centered
class="${this.css({ flex: '1' })}"
label="Suche in selektierten Feldern"
icon="search"
@input="${e => {
const val = e.currentTarget.value;
this.applySearch(val);
}}"
></mwc-textfield>
<mwc-button raised icon="add" @click=${() => this.createNewBasicInstanceAndSave(this.fields.getValue())}>
Frage hinzufügen
</mwc-button>
${this.csvUploadButton()}
</a-inline>
<a-inline size="md">
${rxRepeat(
Content.find({}).pipe(map(contents => [...new Set(contents.map(content => content.Rechtsgebiet))])),
......@@ -109,7 +111,7 @@ export class CCBContentsAdmin extends AdornisDBView<Content> {
this.applySearch('');
}}
>
${rechtsgebiet}
${rechtsgebiet || 'ohne Rechtsgebiet'}
</mwc-button>
`,
)}
......@@ -368,26 +370,37 @@ export class CCBContentsAdmin extends AdornisDBView<Content> {
secondary
@click="${async () => {
const contents = await this.askForFile('*.csv');
await Promise.all(
contents
.split('\n')
.slice(1)
.map(async line => {
const [type, question, answer, deepnessLevel, date, source, contactName, contactMail] = line.split(';');
// Check if content is new
let contentCheck = await Content.findOne({ Rechtsgebiet: type, Frage: question }).result;
if (!contentCheck) {
contentCheck = new Content({
Rechtsgebiet: type,
Frage: question,
Antwort: answer,
Quelle: source,
Ansprechpartner: contactName + ', ' + contactMail,
});
contentCheck.save().subscribe(console.log);
} else console.log('[UPLOAD] Mult. content skipped - ID:', contentCheck._id, 'Q:', contentCheck.Frage);
}),
);
const array2d = contents.split('\n').map(line => line.split(';'));
console.log(array2d[0][0]);
console.log(array2d[0 + 1][0]);
if (array2d[0][0] === 'A.1') {
console.log('Super!');
} else {
console.log('Nicht Super :(');
}
// await Promise.all(
// contents
// .split('\n')
// .slice(1)
// .map(async line => {
// const [type, question, answer, deepnessLevel, date, source, contactName, contactMail] = line.split(';');
// // Check if content is new
// console.log('Hier loggt Markus jetzt:');
// let contentCheck = await Content.findOne({ Rechtsgebiet: type, Frage: question }).result;
// if (!contentCheck) {
// contentCheck = new Content({
// Rechtsgebiet: type,
// Frage: question,
// Antwort: answer,
// Quelle: source,
// Ansprechpartner: contactName + ', ' + contactMail,
// });
// // contentCheck.save().subscribe(console.log);
// console.log(contentCheck);
// } else console.log('[UPLOAD] Mult. content skipped - ID:', contentCheck._id, 'Q:', contentCheck.Frage);
// }),
// );
}}"
>
CSV hochladen!
......@@ -405,4 +418,15 @@ export class CCBContentsAdmin extends AdornisDBView<Content> {
</mwc-button>
`;
}
protected filterForNoIntent() {
return html`
<mwc-button
?raised=${this.filterForNoIntentField}
@click=${() => this.filterForNoIntentField.next(!this.filterForNoIntentField.getValue())}
>
welche haben noch keinen Intent?
</mwc-button>
`;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment