Compare commits
2 Commits
7be11d211f
...
b038e42542
Author | SHA1 | Date | |
---|---|---|---|
b038e42542 | |||
f7aeb280ab |
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
/dist/
|
||||
/node_modules/
|
||||
/package-lock.json
|
||||
/*.json
|
||||
|
6
getWikiAssets.py
Normal file
6
getWikiAssets.py
Normal 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
68
src/ToolsLabelText.vue
Normal 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
36
src/mediawiki.d.ts
vendored
Normal 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 };
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user