You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following snippet of code, if added to a django-sql-dashboard view, will do the trick whenever it sees a pad_bbl column:
/** * @param element {Element} * @returns {number|null} */functionfindIndexInParent(element){constparent=element.parentNode;if(parent){for(leti=0;i<parent.children.length;i++){constchild=parent.children[i];if(child===element)returni;}}returnnull;}/** * @param element {Element} * @returns {HTMLTableElement|null} */functiongetTableAncestor(element){letparent=element.parentNode;while(parent){if(parentinstanceofHTMLTableElement){returnparent;}parent=parent.parentNode;}returnnull;}/** * @param name {String} */function*iterColumnValues(name){constheaders=document.querySelectorAll(`th[alt="${name}"]`);for(letheaderofheaders){consttable=getTableAncestor(header);constindex=findIndexInParent(header);if(index!==null&&table){constcells=table.querySelectorAll(`td:nth-child(${index+1})`);for(letcellofcells){yieldcell;}}}}window.addEventListener("load",()=>{for(lettdofiterColumnValues("pad_bbl")){consta=document.createElement("a");constbbl=td.textContent;// TODO: Replace origin w/ settings.WOW_ORIGIN.a.href=`http://whoownswhat.justfix.nyc/en/bbl/${bbl}`;a.target="_blank";a.rel="noopener noreferrer";a.textContent=td.textContent;td.textContent="";td.appendChild(a);}});
Note that we could take this same concept and extend it to other types of fields. For instance, we could make it so that any column called user_id was automatically hyperlinked to the Django admin user change view.
The text was updated successfully, but these errors were encountered:
toolness
added
the
code snippet
Temporary code that we only need to run once and don't need to merge for long-term use.
label
May 20, 2021
The following snippet of code, if added to a django-sql-dashboard view, will do the trick whenever it sees a
pad_bbl
column:Note that we could take this same concept and extend it to other types of fields. For instance, we could make it so that any column called
user_id
was automatically hyperlinked to the Django admin user change view.The text was updated successfully, but these errors were encountered: