issue-pane
Version:
Solid-compatible Panes: issue editor
1 lines • 11.3 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("UI"),require("SolidLogic"),require("$rdf")):"function"==typeof define&&define.amd?define(["UI","SolidLogic","$rdf"],t):"object"==typeof exports?exports.issue=t(require("UI"),require("SolidLogic"),require("$rdf")):e.issue=t(e.UI,e.SolidLogic,e.$rdf)}(this,(e,t,n)=>(()=>{"use strict";var s={264:e=>{e.exports=n},324:(e,t,n)=>{n.d(t,{newIssueForm:()=>o});var s=n(426),r=n(264);function o(e,t,n,o,i){const a=e.createElement("div"),l=t.any(n,s.ns.wf("stateStore")),c=t.any(n,s.ns.wf("issueClass")),d=s.utils.label(c);a.innerHTML="<h2>Add new "+(o?"sub ":"")+d+"</h2><p>Title of new "+d+":</p>";const u=e.createElement("input");return u.setAttribute("type","text"),u.setAttribute("style","margin: 0.5em; font-size: 100%; padding: 0.3em;"),u.setAttribute("size","100"),u.setAttribute("maxLength","2048"),u.select(),u.addEventListener("keyup",function(e){13===e.keyCode&&function(){u.setAttribute("class","pendingedit"),u.disabled=!0;const e=[],c=t.anyValue(n,s.ns.wf("issueURITemplate")),d=c?t.sym(function(e){const t=new r.Literal(new Date),n=""+(new Date).getTime(),s=t.value.slice(0,4),o=t.value.slice(5,7),i=t.value.slice(8,10);return e.replace("{N}",n).replace("{YYYY}",s).replace("{MM}",o).replace("{DD}",i)}(r.uri.join(c,l.uri))):t.sym(l.uri+"#Iss"+(new Date).getTime()),p=d.doc(),f=t.literal(u.value);e.push(new r.Statement(d,s.ns.wf("tracker"),n,l)),e.push(new r.Statement(d,s.ns.dc("title"),f,l)),e.push(new r.Statement(d,s.ns.dct("created"),new Date,l));const h=o?t.each(o,s.ns.rdf("type"),null,o.doc()):t.each(n,s.ns.wf("initialState"));for(const t of h)e.push(new r.Statement(d,s.ns.rdf("type"),t,l));o&&e.push(new r.Statement(o,s.ns.wf("dependent"),d,l)),c&&(e.push(new r.Statement(d,s.ns.wf("tracker"),n,p)),e.push(new r.Statement(d,s.ns.rdfs("seeAlso"),l,p))),t.updater.update([],e,function(e,t,n){t?(a.parentNode.removeChild(a),i(d)):console.log("Error: can't save new issue:"+n)})}()},!1),a.appendChild(u),u.focus(),a}},426:t=>{t.exports=e},663:e=>{e.exports=t}},r={};function o(e){var t=r[e];if(void 0!==t)return t.exports;var n=r[e]={exports:{}};return s[e](n,n.exports,o),n.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};o.r(i),o.d(i,{CLOSED_TASK_ICON:()=>g,OPEN_TASK_ICON:()=>h,TASK_ICON:()=>f,exposeOverlay:()=>v,getBackgroundColorFromTypes:()=>b,getState:()=>y,iconForIssue:()=>w,isOpen:()=>m,renderIssue:()=>S,renderIssueCard:()=>C});var a=o(426),l=o(663),c=o(324),d=o(264);const u=l.store,p=!1,f=a.icons.iconBase+"noun_17020_gray-tick.svg",h=a.icons.iconBase+"noun_17020_sans-tick.svg",g=a.icons.iconBase+"noun_17020.svg";function m(e){return!!u.findTypeURIs(e)[a.ns.wf("Open").uri]}function w(e){return m(e)?f:g}function y(e,t){const n=u.the(e,a.ns.wf("tracker"),null,e.doc()),s=u.any(n,a.ns.wf("issueClass"));t=t||s;const r=u.each(e,a.ns.rdf("type")).filter(e=>u.holds(e,a.ns.rdfs("subClassOf"),t));if(1!==r.length)throw new Error("Issue must have one type as state: "+r.length);return r[0]}function b(e){const t=u.each(e,a.ns.rdf("type")).map(e=>u.any(e,a.ns.ui("backgroundColor"))).filter(e=>!!e);return t.length?t[0].value:null}function C(e,t){function n(){const t=b(e)||"white";o.style.backgroundColor=t,c.style.backgroundColor=t}const s=t.dom,r=!b(e),o=s.createElement("div"),i=o.appendChild(s.createElement("table"));i.style.width="100%",i.appendChild(a.widgets.personTR(s,null,e,{draggable:!1})),i.subject=e,o.style="border-radius: 0.4em; border: 0.05em solid grey; margin: 0.3em;",o.firstChild.firstChild.firstChild.firstChild.setAttribute("src",a.icons.iconBase+"noun_Danger_1259514.svg");const l=o.firstChild.firstChild.children[2],c=a.widgets.button(s,a.icons.iconBase+"noun_253504.svg","edit",async n=>{v(e,t)}),d=c.firstChild;if(d.style.width=d.style.height="1.5em",l.appendChild(c),r){const n=a.widgets.deleteButtonWithCheck(s,l,"issue",async function(){try{await u.updater.update(u.connectedStatements(e))}catch(e){!function(e,t){console.warn(e),t.paneDiv.appendChild(a.widgets.errorMessageBlock(t.dom,e))}(`Unable to delete issue: ${e}`,t)}console.log("User deleted issue "+e),o.parentNode.removeChild(o),a.widgets.refreshTree(t.paneDiv)});l.appendChild(n)}return o.style.maxWidth="24em",o.refresh=n,n(),o}function v(e,t){const n=t.overlay;n.innerHTML="";const s=n.appendChild(a.widgets.button(t.dom,a.icons.iconBase+"noun_1180156.svg","close",function(){n.innerHTML="",n.style.visibility="hidden"}));s.style.float="right",s.style.margin="0.7em",delete s.style.backgroundColor,n.style.visibility="visible",n.appendChild(S(e,t)),n.firstChild.style.overflow="auto"}function x(e,t){const n=e.createElement("div");return n.setAttribute("style","height: 1em; margin: 0.5em;"),n.style.backgroundColor=t,n}function S(e,t){function n(t,n,s){if(p){if(!i(h,"trackLastModified"))return;const t=n.statementsMatching(e,a.ns.dct("modified")).concat(n.statementsMatching(e,a.ns.wf("modifiedBy"))),r=[d.st(e,a.ns.dct("modified"),new Date,s)];C&&r.push(d.st(e,a.ns.wf("modifiedBy"),C,s)),n.updater.update(t,r,function(e,t,n){})}}function s(e,t){const n=f.createElement("pre");return n.setAttribute("style",t||"color: grey"),y.appendChild(n),n.appendChild(f.createTextNode(e)),n}function r(e){console.warn(e),y.appendChild(a.widgets.errorMessageBlock(f,e))}function o(e,t){e||r("Sorry, failed to save your change:\n"+t)}function i(e,t){const n=u.any(e,a.ns.ui(t));return!(!n||!n.value)}const f=t.dom,h=u.the(e,a.ns.wf("tracker"),null,e.doc());if(!h)throw new Error("No tracker");const g=u.any(h,a.ns.wf("stateStore")),m=e.doc(),y=f.createElement("div"),C=l.authn.currentUser(),v=b(e)||"white";!function(){const t="padding: 0.5em 1.5em 1em 1.5em; border: 0.7em;border-color: "+(b(e)||"#eee")+"; ";y.setAttribute("style",t),y.style.backgroundColor="white"}(),l.authn.checkUser();const S=y.appendChild(a.widgets.button(f,w(e)));a.widgets.makeDraggable(S,e);const k=u.any(h,a.ns.wf("issueClass"));if(!k)throw new Error("This tracker "+h+" has no issueClass");const T=a.widgets.makeSelectForCategory(f,u,e,k,g,function(e,t){e?(n(0,u,m),a.widgets.refreshTree(y)):console.log("Failed to change state:\n"+t)});y.appendChild(T);const E=u.each(h,a.ns.wf("issueCategory"));for(const t of E)y.appendChild(a.widgets.makeSelectForCategory(f,u,e,t,g,function(e,t){e?(n(0,u,m),a.widgets.refreshTree(y)):console.log("Failed to change category:\n"+t)}));const F=f.createElement("a");F.setAttribute("href",h.uri),F.setAttribute("style","float:right"),y.appendChild(F).textContent=a.utils.label(h),F.addEventListener("click",a.widgets.openHrefInOutlineMode,!0);const I=a.ns.wf("coreIsueForm");d.parse('\n @prefix : <http://www.w3.org/ns/ui#> .\n @prefix core: <http://www.w3.org/2005/01/wf/flow#>.\n @prefix dc: <http://purl.org/dc/elements/1.1/>.\n @prefix wf: <http://www.w3.org/2005/01/wf/flow#> .\n\n core:coreIsueForm a :Form;\n <http://purl.org/dc/elements/1.1/title> "Core issue data";\n :parts (\n core:titleField\n core:descriptionField ) .\n\n core:descriptionField a :MultiLineTextField;\n :label "Description";\n :property wf:description;\n :size "40" .\n\n core:titleField a :SingleLineTextField;\n :label "Title";\n :maxLength "128";\n :property dc:title; # @@ Should move to dct or schema\n :size "40" .\n\n wf:Task :creationForm core:coreIsueForm .\n',u,I.doc().uri,"text/turtle");const A=a.widgets.appendForm(f,null,{},e,I,g,o);y.appendChild(A),A.style.backgroundColor=v;const L=u.statementsMatching(e,a.ns.wf("assignee"));if(L.length>1){s("Weird, was assigned to more than one person. Fixing ..");const e=L.slice(1);u.updater.update(e,[],function(e,t,n){t?s("Now fixed."):r("Fixed failed: "+n)})}function O(e){return a.widgets.personTR(f,a.ns.wf("dependent"),e,{link:!1})}function D(e,t){t=t||[];const n=u.any(null,a.ns.wf("dependent"),e,e.doc());return n?D(n,[n].concat(t)):t}if(async function(){const t=u.each(e,a.ns.wf("assigneeGroup"));await u.fetcher.load(t);const n=t.map(e=>u.each(e,a.ns.vcard("member"),null,e.doc())).flat(),s=u.any(null,a.ns.doap("bug-database"),h);s&&await u.fetcher.load(s);const r=s?u.each(s,a.ns.doap("developer")):[];return n.concat(r)}().then(t=>{if(t.length){t.forEach(function(e){u.fetcher.lookUpThing(e)});const s={nullLabel:"(unassigned)"};y.appendChild(a.widgets.makeSelectForOptions(f,u,e,a.ns.wf("assignee"),t,s,m,function(e,t){e?n(0,u,m):console.log("Failed to change assignee:\n"+t)}))}}),i(h,"allowSubIssues")){const t=y.appendChild(f.createElement("div"));t.style="margin: 1em; padding: 1em;",t.appendChild(f.createElement("h4")).textContent="Super Issues";const n=t.appendChild(f.createElement("div"));n.style.display="flex",n.refresh=function(){const t=D(e);a.utils.syncTableToArrayReOrdered(n,t,O)},n.refresh(),t.appendChild(f.createElement("h4")).textContent="Sub Issues";const s=t.appendChild(f.createElement("div"));s.style.display="flex",s.style.flexDirection="reverse",s.refresh=function(){const t=u.each(e,a.ns.wf("dependent"),null,e.doc());a.utils.syncTableToArrayReOrdered(s,t,O)},s.refresh();const r=f.createElement("button");r.setAttribute("type","button"),t.appendChild(r);const o=a.utils.label(k);r.innerHTML="New sub "+o,r.setAttribute("style","float: right; margin: 0.5em 1em;"),r.addEventListener("click",function(n){t.insertBefore((0,c.newIssueForm)(f,u,h,e,s.refresh),r.nextSibling)},!1)}y.appendChild(f.createElement("br"));const _=u.any(h,a.ns.wf("extrasEntryForm"));_&&a.widgets.appendForm(f,y,{},e,_,g,o);const B=y.appendChild(x(f,v));let M;u.anyValue(h,a.ns.wf("issueURITemplate"))?M=e.doc():(M=u.any(h,a.ns.wf("messageStore")),M||(M=u.any(h,a.ns.wf("stateStore"))),u.sym(M.uri+"#Chat"+(new Date).getTime())),u.fetcher.nowOrWhenFetched(M,function(t,n,s){if(t){const t=(0,a.messageArea)(f,u,e,M);y.insertBefore(t,B),y.insertBefore(x(f,v),t)}else{const e=f.createElement("p");e.textContent=n,y.insertBefore(e,B)}}),y.appendChild(f.createElement("div")).innerHTML="<h4>Attachments</h4>\n <p>Drag files, emails,\n web pages onto the paper clip, or click the file upload button.</p>";const U=e.uri.endsWith("/index.ttl#this")?e.uri.slice(0,14)+"Files/":e.dir().uri+"Files/"+e.uri.split("#")[1]+"/";a.widgets.attachmentList(f,e,y,{doc:g,promptIcon:a.icons.iconBase+"noun_25830.svg",uploadFolder:u.sym(U),predicate:a.ns.wf("attachment")}),a.widgets.deleteButtonWithCheck(f,y,"issue",async function(){try{await u.updater.update(u.connectedStatements(e))}catch(e){r(`Unable to delete issue: ${e}`)}r("DELETED OK"),y.style.backgroundColor="#eee",y.style.fontColor="orange"}).style.float="right";const N=f.createElement("button");return N.textContent="refresh messages",N.addEventListener("click",async function(e){try{await u.fetcher.load(M,{force:!0,clearPreviousData:!0})}catch(e){return void alert(e)}a.widgets.refreshTree(y)},!1),N.setAttribute("style",a.style.button),y.appendChild(N),y}return i})());