Skip to content

Commit

Permalink
Mkarimi/version filter template (#132)
Browse files Browse the repository at this point in the history
* Filter results by version in vue template

* Filter data type by version

* Add overloads to search results

* Fix non existing version filter
  • Loading branch information
karimi authored Jun 4, 2024
1 parent f319c4f commit 7ab7a2d
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 153 deletions.
110 changes: 20 additions & 90 deletions quasar_site/src/ViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ let _searchInstance = null;
let _selectedPath = "";
let _lastFound = null;
let _pathMap = {};
let _maxVersion = null;

let updateTree = (path, children) => (obj) => {
if (obj.path === path) {
Expand Down Expand Up @@ -152,26 +151,13 @@ const ViewModel = {
_viewmodel = null;
_searchInstance = null;
},
setMaxVersion(v) {
_maxVersion = v;
},
getTree() {
if (_viewmodel) return _viewmodel;
let viewmodel = null;
{
// console.log('creating viewodel')
const namespaceDict = {};
ApiInfo.forEach((type) => {
if (
_maxVersion &&
type.since &&
this.sinceIsGreater(type.since, _maxVersion)
) {
// console.log(
// `not including ${type.name} because ${type.since} is newer than ${_maxVersion}`
// );
return;
}
let summary = "";
if (type.summary) summary = type.summary;
if (type.dataType === DataTypes.NAMESPACE) {
Expand Down Expand Up @@ -249,13 +235,6 @@ const ViewModel = {
let found = null;

if (_lastFound && this.itemPath(_lastFound) === path) {
if (
_maxVersion &&
_lastFound.since &&
this.sinceIsGreater(_lastFound.since, _maxVersion)
) {
return;
}
return _lastFound;
}

Expand All @@ -265,14 +244,6 @@ const ViewModel = {
});
_lastFound = found;

if (
found &&
_maxVersion &&
found.since &&
this.sinceIsGreater(found.since, _maxVersion)
) {
return;
}
return found;
},
setSelectedItem(item, updateRoute = true) {
Expand Down Expand Up @@ -496,17 +467,6 @@ const ViewModel = {
getSearchList() {
const items = [];
ApiInfo.forEach((entry) => {
// skip namespaces
if (
_maxVersion &&
entry.since &&
this.sinceIsGreater(entry.since, _maxVersion)
) {
// console.log(
// `not including ${entry.name} because ${entry.since} is newer than ${_maxVersion}`
// );
return;
}
if (entry.dataType === "namespace") return;
const dataTypeUrl = (entry.namespace + "." + entry.name).toLowerCase();
const typename = entry.namespace + "." + entry.name;
Expand All @@ -521,18 +481,14 @@ const ViewModel = {
items.push(node);
if (entry.properties) {
entry.properties.forEach((prop) => {
if (
_maxVersion &&
prop.since &&
this.sinceIsGreater(prop.since, _maxVersion)
) {
return;
}
const chunks = prop.signature.split(" ");
node = { typename: typename, member: chunks[chunks.length - 1] };
if (items[items.length - 1].member === node.member) return;
node.type = "property";
node.url = dataTypeUrl + "/" + node.member.toLowerCase();
node.url = `${dataTypeUrl}/${node.member.toLowerCase()}#${this.signatureAnchorRef(
prop.signature
)}`;
node.since = entry.since;
node.keywords =
dataTypeUrl.replaceAll(".", " ") + " " + node.member.toLowerCase();
if (prop.summary) node.summary = prop.summary;
Expand All @@ -541,19 +497,14 @@ const ViewModel = {
}
if (entry.methods) {
entry.methods.forEach((method) => {
if (
_maxVersion &&
method.since &&
this.sinceIsGreater(method.since, _maxVersion)
) {
return;
}
let chunks = method.signature.split("(");
chunks = chunks[0].split(" ");
node = { typename: typename, member: chunks[chunks.length - 1] };
if (items[items.length - 1].member === node.member) return;
node.type = "method";
node.url = dataTypeUrl + "/" + node.member.toLowerCase();
node.url = `${dataTypeUrl}/${node.member.toLowerCase()}#${this.signatureAnchorRef(
method.signature
)}`;
node.since = method.since;
node.keywords =
dataTypeUrl.replaceAll(".", " ") + " " + node.member.toLowerCase();
if (method.summary) node.summary = method.summary;
Expand All @@ -562,18 +513,14 @@ const ViewModel = {
}
if (entry.events) {
entry.events.forEach((event) => {
if (
_maxVersion &&
event.since &&
this.sinceIsGreater(event.since, _maxVersion)
) {
return;
}
const chunks = event.signature.split(" ");
node = { typename: typename, member: chunks[chunks.length - 1] };
if (items[items.length - 1].member === node.member) return;
node.type = "event";
node.url = dataTypeUrl + "/" + node.member.toLowerCase();
node.url = `${dataTypeUrl}/${node.member.toLowerCase()}#${this.signatureAnchorRef(
event.signature
)}`;
node.since = event.since;
node.keywords =
dataTypeUrl.replaceAll(".", " ") + " " + node.member.toLowerCase();
if (event.summary) node.summary = event.summary;
Expand All @@ -582,18 +529,14 @@ const ViewModel = {
}
if (entry.operators) {
entry.operators.forEach((operator) => {
if (
_maxVersion &&
operator.since &&
this.sinceIsGreater(operator.since, _maxVersion)
) {
return;
}
const chunks = operator.signature.split(" ");
node = { typename: typename, member: chunks[chunks.length - 1] };
if (items[items.length - 1].member === node.member) return;
node.type = "operator";
node.url = dataTypeUrl + "/" + node.member.toLowerCase();
node.url = `${dataTypeUrl}/${node.member.toLowerCase()}#${this.signatureAnchorRef(
operator.signature
)}`;
node.since = operator.since;
node.keywords =
dataTypeUrl.replaceAll(".", " ") + " " + node.member.toLowerCase();
if (operator.summary) node.summary = operator.summary;
Expand All @@ -602,19 +545,14 @@ const ViewModel = {
}
if (entry.fields) {
entry.fields.forEach((field) => {
//TODO: review
if (
_maxVersion &&
field.since &&
this.sinceIsGreater(field.since, _maxVersion)
) {
return;
}
const chunks = field.signature.split(" ");
node = { typename: typename, member: chunks[chunks.length - 1] };
if (items[items.length - 1].member === node.member) return;
node.type = "field";
node.url = dataTypeUrl + "/" + node.member.toLowerCase();
node.url = `${dataTypeUrl}/${node.member.toLowerCase()}#${this.signatureAnchorRef(
field.signature
)}`;
node.since = field.since;
node.keywords =
dataTypeUrl.replaceAll(".", " ") + " " + node.member.toLowerCase();
if (field.summary) node.summary = field.summary;
Expand All @@ -631,14 +569,6 @@ const ViewModel = {

if (node[memberType]) {
for (let i = 0; i < members.length; i++) {
if (
_maxVersion &&
members[i].since &&
this.sinceIsGreater(members[i].since, _maxVersion)
) {
// console.log(`not including ${members[i]}`);
return;
}
members[i].parent = node.namespace + "." + node.name;
members[i].namespace = node.namespace;
const url = this.memberUrl(memberType, members[i]);
Expand Down
12 changes: 2 additions & 10 deletions quasar_site/src/layouts/MainLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ export default {
},
data() {
const mostRecent = ViewModel.mostRecentSince();
ViewModel.setMaxVersion(mostRecent);
const vm = ViewModel.getTree(mostRecent);
const vm = ViewModel.getTree();
const $q = useQuasar();
return {
leftDrawerOpen: false,
Expand Down Expand Up @@ -120,14 +119,7 @@ export default {
methods: {
onChangeVersionFilter (item) {
this.filterVersion = item;
if (this.$route.query["version"] != item){
ViewModel.resetTree();
ViewModel.setMaxVersion(item);
this.api = ViewModel.getTree();
this.$router.push({ query: { version: item } }).then( () =>{
window.location.reload(); //
})
}
this.$router.push({ query: { ...this.$route.query, version: item } })
},
filterTocByVersion (node, filter) {
if(node.since){
Expand Down
Loading

0 comments on commit 7ab7a2d

Please sign in to comment.