Compare commits

..

2 Commits

Author SHA1 Message Date
b038e42542 WIP: Retrieve data from mediawiki for tools 2022-10-05 13:58:42 -04:00
f7aeb280ab Ignore data files 2022-10-05 13:57:23 -04:00
4 changed files with 111 additions and 0 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
/dist/
/node_modules/
/package-lock.json
/*.json

6
getWikiAssets.py Normal file
View File

@ -0,0 +1,6 @@
import requests
r = requests.get('https://wiki.claremontmakerspace.org/api.php?action=askargs&conditions=Asset Tag::%2B&printouts=Asset Tag|Requires Certification|Has Reservation URL&format=json&api_version=2')
with open('wiki-tools.json', 'w') as f:
f.write(r.text)

68
src/ToolsLabelText.vue Normal file
View File

@ -0,0 +1,68 @@
<template>
<span class="text-content">
<div class="name">{{ decodedName }}</div>
<!-- <div class="name">{{ asset.model.name }}</div> -->
<!-- ideas: model info? -->
<div class="certification">Certification: {{ certification }}</div>
<div class="reservation">Reservation: {{ reservation }}</div>
</span>
</template>
<script setup lang="ts">
import { computed, ComputedRef, defineProps } from 'vue';
import snipeit from './snipeit';
import mediawiki from './mediawiki';
import wikiTools from '../wiki-tools.json';
const props = defineProps<{
asset: snipeit.Hardware;
}>();
const decodedName: ComputedRef<string> = computed(() => {
const doc = new DOMParser().parseFromString(props.asset.name, 'text/html');
return doc.documentElement.textContent ?? 'invalid name!';
});
const wikiTool: ComputedRef<mediawiki.AskResult | undefined> = computed(() => {
return Object.values((wikiTools as mediawiki.apiAsk).query.results).find(
(x) => x.printouts['Asset Tag'].includes(props.asset.asset_tag)
);
});
const certification: ComputedRef<string> = computed(() => {
if (!wikiTool) {
return 'Unknown';
}
return (
wikiTool.value?.printouts[
'Requires Certification'
][0] as mediawiki.PageValue
).fulltext;
});
const reservation: ComputedRef<string> = computed(() => {
if (!wikiTool) {
return 'Unknown';
}
let reservationLinks = wikiTool.value?.printouts['Has Reservation URL'];
return reservationLinks && reservationLinks.length === 0 ? 'No' : 'Yes';
});
</script>
<style scoped>
.text-content {
font-family: monospace;
font-size: 10px;
line-height: 1;
}
.name {
text-decoration: underline;
}
.certification {
font-size: 10px;
}
</style>

36
src/mediawiki.d.ts vendored Normal file
View File

@ -0,0 +1,36 @@
export interface PrintRequest {
label: string;
key: string;
redi: string;
typeid: string;
mode: number;
}
export interface PageValue {
fulltext: string;
fullurl: string;
namespace: number;
exists: string; // TODO: might be '0'|'1'
displaytitle: string;
}
// TODO: more prop types exist
export type PropValue = string | PageValue;
export interface AskResult {
printouts: {
[prop: string]: PropValue[];
};
fulltext: string;
fullurl: string;
namespace: number;
exists: string; // TODO: might be '0'|'1'
displaytitle: string;
}
export interface apiAsk {
query: {
printrequests: PrintRequest[];
results: { [name: string]: AskResult };
};
}