reqtable 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reqtable/__init__.py +3 -0
- reqtable/__main__.py +3 -0
- reqtable/baselines.py +920 -0
- reqtable/cli.py +631 -0
- reqtable/comparison.py +63 -0
- reqtable/core.py +1448 -0
- reqtable/drafts.py +166 -0
- reqtable/findings.py +605 -0
- reqtable/gate_checks.py +84 -0
- reqtable/gates.py +348 -0
- reqtable/glossary.py +162 -0
- reqtable/gui.py +952 -0
- reqtable/gui_lookups.py +192 -0
- reqtable/gui_mapping.py +789 -0
- reqtable/gui_page.py +691 -0
- reqtable/gui_page_gates.py +173 -0
- reqtable/gui_page_mapping.py +390 -0
- reqtable/gui_server.py +467 -0
- reqtable/html_report.py +2595 -0
- reqtable/markdown.py +127 -0
- reqtable/package.py +163 -0
- reqtable/quality.py +422 -0
- reqtable/review.py +318 -0
- reqtable/signoff.py +179 -0
- reqtable/traceability.py +1670 -0
- reqtable/values.py +192 -0
- reqtable/waivers.py +109 -0
- reqtable/xlsx.py +1108 -0
- reqtable-0.1.0.dist-info/METADATA +106 -0
- reqtable-0.1.0.dist-info/RECORD +33 -0
- reqtable-0.1.0.dist-info/WHEEL +4 -0
- reqtable-0.1.0.dist-info/entry_points.txt +2 -0
- reqtable-0.1.0.dist-info/licenses/LICENSE +21 -0
reqtable/drafts.py
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
DRAFTS_CSS = r"""
|
|
4
|
+
.draft-banner{display:flex;flex-wrap:wrap;align-items:center;gap:6px 8px;margin:0 0 6px;padding:5px 9px;background:var(--panel);color:var(--text);border:1px solid var(--accent);border-radius:6px}
|
|
5
|
+
.draft-banner[hidden]{display:none}
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
DRAFTS_HTML = """<div id="draft-banner" class="draft-banner" role="region" aria-label="Unsaved draft" hidden><span id="draft-message" role="status"></span><button id="draft-restore" type="button">Restore</button><button id="draft-download" type="button">Download CSV</button><button id="draft-discard" type="button">Discard</button></div>"""
|
|
9
|
+
|
|
10
|
+
DRAFTS_JS = r"""
|
|
11
|
+
const DRAFT_MAX_AGE_MS=30*24*60*60*1000,DRAFT_DELAY_MS=1000;
|
|
12
|
+
function csvField(value,delimiter){const text=String(value??"");return(/["\r\n]/.test(text)||text.includes(delimiter))?'"'+text.replace(/"/g,'""')+'"':text;}
|
|
13
|
+
function csvText(headers,rows,delimiter){
|
|
14
|
+
const lines=[headers.map(x=>csvField(x,delimiter)).join(delimiter)];
|
|
15
|
+
for(const row of rows)lines.push(headers.map(h=>csvField(row[h]??"",delimiter)).join(delimiter));
|
|
16
|
+
return""+lines.join("\r\n")+"\r\n";
|
|
17
|
+
}
|
|
18
|
+
function reportFingerprint(table){
|
|
19
|
+
const text=JSON.stringify([table.headers,table.rows]);
|
|
20
|
+
let hash=2166136261;
|
|
21
|
+
for(let i=0;i<text.length;i++)hash=Math.imul(hash^text.charCodeAt(i),16777619);
|
|
22
|
+
return (hash>>>0).toString(16)+"-"+text.length;
|
|
23
|
+
}
|
|
24
|
+
function changedRowCount(baseRows,rows,idOf){
|
|
25
|
+
const before=new Map(baseRows.map(row=>[idOf(row),JSON.stringify(row)])),after=new Map(rows.map(row=>[idOf(row),JSON.stringify(row)]));
|
|
26
|
+
let count=0;
|
|
27
|
+
for(const [id,json] of after)if(before.get(id)!==json)count++;
|
|
28
|
+
for(const id of before.keys())if(!after.has(id))count++;
|
|
29
|
+
return count;
|
|
30
|
+
}
|
|
31
|
+
function changedCommentCount(saved,comments){
|
|
32
|
+
const before=new Set(saved.map(c=>JSON.stringify(c))),after=new Set(comments.map(c=>JSON.stringify(c)));
|
|
33
|
+
return Math.max([...after].filter(json=>!before.has(json)).length,[...before].filter(json=>!after.has(json)).length);
|
|
34
|
+
}
|
|
35
|
+
function buildDraft({path,fingerprint,title,headers,rows,baseRows,comments,savedComments,rowsDirty,commentsDirty,idOf,now,decisions=[],decisionsDirty=false}){
|
|
36
|
+
return {key:path,fingerprint,savedAt:now.toISOString(),title,headers:[...headers],
|
|
37
|
+
rows:rowsDirty?JSON.parse(JSON.stringify(rows)):null,
|
|
38
|
+
comments:commentsDirty?JSON.parse(JSON.stringify(comments)):null,
|
|
39
|
+
changedCount:rowsDirty?changedRowCount(baseRows,rows,idOf):0,
|
|
40
|
+
changedComments:commentsDirty?changedCommentCount(savedComments,comments):0,
|
|
41
|
+
decisions:decisionsDirty?JSON.parse(JSON.stringify(decisions)):null};
|
|
42
|
+
}
|
|
43
|
+
function draftIsStale(record,now){
|
|
44
|
+
const age=now-Date.parse(record.savedAt);
|
|
45
|
+
return !(age<=DRAFT_MAX_AGE_MS);
|
|
46
|
+
}
|
|
47
|
+
function draftOffer({record,fingerprint,developMode,savedRows,savedComments,savedDecisions=[]}){
|
|
48
|
+
if(!record)return null;
|
|
49
|
+
if(record.fingerprint!==fingerprint)return developMode&&record.rows?"download":null;
|
|
50
|
+
const rows=developMode&&record.rows&&JSON.stringify(record.rows)!==JSON.stringify(savedRows),
|
|
51
|
+
comments=record.comments&&JSON.stringify(record.comments)!==JSON.stringify(savedComments),
|
|
52
|
+
decisions=record.decisions&&JSON.stringify(record.decisions)!==JSON.stringify(savedDecisions);
|
|
53
|
+
return rows||comments||decisions?"restore":null;
|
|
54
|
+
}
|
|
55
|
+
function draftMessage(record,offer,formatDate){
|
|
56
|
+
const when=formatDate(record.savedAt),count=(n,noun)=>`${n} ${noun}${n===1?"":"s"} changed`;
|
|
57
|
+
if(offer==="download")return`Unsaved edits from an earlier version of this report (${when}).`;
|
|
58
|
+
const parts=[];
|
|
59
|
+
if(record.rows)parts.push(count(record.changedCount,"row"));
|
|
60
|
+
if(record.comments)parts.push(count(record.changedComments,"comment"));
|
|
61
|
+
if(record.decisions)parts.push("decisions changed");
|
|
62
|
+
return`Unsaved edits from ${when}`+(parts.length?` (${parts.join(", ")}).`:".");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const draftStore={
|
|
66
|
+
run(mode,work){
|
|
67
|
+
return new Promise(resolve=>{
|
|
68
|
+
try{
|
|
69
|
+
const opening=indexedDB.open("reqtable-drafts",1);
|
|
70
|
+
opening.onupgradeneeded=()=>opening.result.createObjectStore("drafts",{keyPath:"key"});
|
|
71
|
+
opening.onerror=opening.onblocked=()=>resolve(undefined);
|
|
72
|
+
opening.onsuccess=()=>{
|
|
73
|
+
const db=opening.result;
|
|
74
|
+
try{
|
|
75
|
+
const tx=db.transaction("drafts",mode),request=work(tx.objectStore("drafts"));
|
|
76
|
+
tx.oncomplete=()=>{db.close();resolve(request?.result);};
|
|
77
|
+
tx.onerror=tx.onabort=()=>{db.close();resolve(undefined);};
|
|
78
|
+
}catch{db.close();resolve(undefined);}
|
|
79
|
+
};
|
|
80
|
+
}catch{resolve(undefined);}
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
get:key=>draftStore.run("readonly",store=>store.get(key)),
|
|
84
|
+
put:record=>draftStore.run("readwrite",store=>store.put(record)),
|
|
85
|
+
remove:key=>draftStore.run("readwrite",store=>store.delete(key)),
|
|
86
|
+
prune:now=>draftStore.run("readwrite",store=>{
|
|
87
|
+
store.openCursor().onsuccess=event=>{
|
|
88
|
+
const cursor=event.target.result;
|
|
89
|
+
if(!cursor)return;
|
|
90
|
+
if(draftIsStale(cursor.value,now))cursor.delete();
|
|
91
|
+
cursor.continue();
|
|
92
|
+
};
|
|
93
|
+
})
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const drafts={phase:"none",timer:0,record:null,enabled:false,fingerprint:""};
|
|
97
|
+
function draftWanted(){return $("#autosave").checked&&(state.commentsDirty||(developMode()&&state.requirementsDirty)||state.decisionsDirty);}
|
|
98
|
+
function draftChanged(){
|
|
99
|
+
if(!drafts.enabled||drafts.phase==="offered")return;
|
|
100
|
+
clearTimeout(drafts.timer);
|
|
101
|
+
if(draftWanted()){
|
|
102
|
+
drafts.phase="pending";
|
|
103
|
+
drafts.timer=setTimeout(draftFlush,DRAFT_DELAY_MS);
|
|
104
|
+
}else if(drafts.phase!=="none"){
|
|
105
|
+
drafts.phase="none";
|
|
106
|
+
draftStore.remove(location.pathname);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function draftFlush(){
|
|
110
|
+
clearTimeout(drafts.timer);
|
|
111
|
+
if(drafts.phase!=="pending")return;
|
|
112
|
+
drafts.phase="written";
|
|
113
|
+
draftStore.put(buildDraft({path:location.pathname,fingerprint:drafts.fingerprint,title:data.meta.title,
|
|
114
|
+
headers:data.source.new.headers,rows:state.currentRows,baseRows:data.source.new.rows,comments:state.comments,
|
|
115
|
+
savedComments:state.savedComments,rowsDirty:developMode()&&state.requirementsDirty,commentsDirty:state.commentsDirty,
|
|
116
|
+
idOf:rowId,now:new Date(),decisions:state.decisions,decisionsDirty:state.decisionsDirty}));
|
|
117
|
+
}
|
|
118
|
+
function closeDraftBanner(){
|
|
119
|
+
$("#draft-banner").hidden=true;
|
|
120
|
+
drafts.record=null;
|
|
121
|
+
drafts.phase="none";
|
|
122
|
+
}
|
|
123
|
+
async function draftsStart(){
|
|
124
|
+
if(!window.indexedDB||!(developMode()||data.options.commentsEnabled))return;
|
|
125
|
+
drafts.fingerprint=reportFingerprint(data.source.new);
|
|
126
|
+
await draftStore.prune(Date.now());
|
|
127
|
+
const record=await draftStore.get(location.pathname),
|
|
128
|
+
offer=draftOffer({record,fingerprint:drafts.fingerprint,developMode:developMode(),savedRows:state.savedRows,savedComments:state.savedComments,savedDecisions:state.savedDecisions});
|
|
129
|
+
drafts.enabled=true;
|
|
130
|
+
if(offer&&!state.dirty){
|
|
131
|
+
drafts.record=record;
|
|
132
|
+
drafts.phase="offered";
|
|
133
|
+
$("#draft-message").textContent=draftMessage(record,offer,iso=>new Date(iso).toLocaleString());
|
|
134
|
+
$("#draft-restore").hidden=offer!=="restore";
|
|
135
|
+
$("#draft-download").hidden=offer!=="download";
|
|
136
|
+
$("#draft-banner").hidden=false;
|
|
137
|
+
}else{
|
|
138
|
+
if(record&&!offer&&record.fingerprint===drafts.fingerprint)draftStore.remove(location.pathname);
|
|
139
|
+
draftChanged();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
$("#draft-restore").addEventListener("click",()=>{
|
|
143
|
+
const record=drafts.record;
|
|
144
|
+
if(!record||(state.dirty&&!confirm("Replace the current changes with the unsaved draft?")))return;
|
|
145
|
+
closeDraftBanner();
|
|
146
|
+
remember();
|
|
147
|
+
if(record.decisions)state.decisions=cloneValue(record.decisions);
|
|
148
|
+
restoreHistory({rows:developMode()&&record.rows?cloneRecords(record.rows):state.currentRows,comments:record.comments?cloneRecords(record.comments):state.comments});
|
|
149
|
+
$("#save-status").textContent="Unsaved edits restored";
|
|
150
|
+
restoreSelectedCell();
|
|
151
|
+
});
|
|
152
|
+
$("#draft-download").addEventListener("click",()=>{
|
|
153
|
+
const record=drafts.record;
|
|
154
|
+
if(!record?.rows)return;
|
|
155
|
+
downloadBlob(new Blob([csvText(record.headers,record.rows,data.options.csvDelimiter||",")],{type:"text/csv;charset=utf-8"}),`${data.meta.baseFilename}-draft.csv`);
|
|
156
|
+
$("#save-status").textContent="Draft CSV download initiated";
|
|
157
|
+
});
|
|
158
|
+
$("#draft-discard").addEventListener("click",()=>{
|
|
159
|
+
draftStore.remove(location.pathname);
|
|
160
|
+
closeDraftBanner();
|
|
161
|
+
draftChanged();
|
|
162
|
+
$("#save-status").textContent="Unsaved draft discarded";
|
|
163
|
+
});
|
|
164
|
+
window.addEventListener("pagehide",draftFlush);
|
|
165
|
+
document.addEventListener("visibilitychange",()=>{if(document.hidden)draftFlush();});
|
|
166
|
+
"""
|