Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Added widget to browse/select locally-edited files. Related cleanups and refactoring. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | fileedit-ajaxify |
| Files: | files | file ages | folders |
| SHA3-256: |
aefceac57c98bda86718ad5b8a546fa5 |
| User & Date: | stephan 2020-05-16 05:03:11.416 |
Context
|
2020-05-16
| ||
| 05:42 | Include the branch name, if known, in stashed fileinfo objects, and use a longer hash prefix for storing checkin-to-branch mappings (noting that the record does not notice if a checkin is later moved to another branch). (We only know the branch names of leaf checkins we've loaded, but now cache them in persistent storage if possible.) Renamed an internal cache key for consistency. ... (check-in: 8573443f32 user: stephan tags: fileedit-ajaxify) | |
| 05:03 | Added widget to browse/select locally-edited files. Related cleanups and refactoring. ... (check-in: aefceac57c user: stephan tags: fileedit-ajaxify) | |
|
2020-05-15
| ||
| 22:13 | Added fileedit-content-replaced event for notification when content is replaced. Clear preview/diff views on fileedit-content-replaced. Changed the interface for providing custom content getter/setter. Fixed the load file button in the file selection widget - it's no longer cleared. ... (check-in: 6f2649b9b0 user: stephan tags: fileedit-ajaxify) | |
Changes
Changes to src/default_css.txt.
| ︙ | ︙ | |||
858 859 860 861 862 863 864 |
// border: 1px solid black;
// vertical-align: top;
// }
// #setup_skinedit_css_defaults > tbody > tr > td:nth-of-type(2) > div {
// max-width: 30em;
// overflow: auto;
// }
| < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
// border: 1px solid black;
// vertical-align: top;
// }
// #setup_skinedit_css_defaults > tbody > tr > td:nth-of-type(2) > div {
// max-width: 30em;
// overflow: auto;
// }
//////////////////////////////////
// Styles for fossil.tabs.js:
.tab-container {
width: 100%;
display: flex;
flex-direction: column;
align-items: stretch;
|
| ︙ | ︙ | |||
946 947 948 949 950 951 952 |
.tab-container > .tab-bar > .tab-button.selected {
text-decoration: underline;
opacity: 1.0;
border-top-style: outset;
border-left-style: outset;
border-right-style: outset;
}
| < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < | < | < | > > | | < < < | < < | | > < | > > | < > > | > | 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 |
.tab-container > .tab-bar > .tab-button.selected {
text-decoration: underline;
opacity: 1.0;
border-top-style: outset;
border-left-style: outset;
border-right-style: outset;
}
////////////////////////////////////////////////////////////////////
// Styles developed for /fileedit but which have wider
// applicability:
.flex-container {
display: flex;
}
.flex-container.flex-row {
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.flex-container .flex-grow {
flex-grow: 10;
flex-shrink: 0;
}
.flex-container .flex-shrink {
flex-grow: 0;
flex-shrink: 10;
}
#fossil-status-bar {
display: block;
font-family: monospace;
border-width: 1px;
border-style: inset;
border-color: inherit;
min-height: 1.5em;
font-size: 1.2em;
padding: 0.2em;
margin: 0.25em 0;
flex: 0 0 auto;
}
.error {
color: darkred;
background: yellow;
}
.warning {
color: darkred;
background: yellow;
opacity: 0.7;
}
.hidden {
position: absolute;
opacity: 0;
pointer-events: none;
}
.flex-container.flex-row.stretch {
flex-wrap: wrap;
align-items: baseline;
justify-content: stretch;
margin: 0;
}
|
| ︙ | ︙ | |||
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 |
}
.font-size-175 {
font-size: 175%;
}
.font-size-200 {
font-size: 200%;
}
//////////////////////////////////////////////////////////////////
// .input-with-label is intended to be a wrapper element which
// contains a SPAN label and an INPUT control.
.input-with-label {
border: 1px inset #808080;
border-radius: 0.5em;
padding: 0.25em 0.4em;
margin: 0 0.5em;
display: inline-block;
cursor: default;
}
.input-with-label > * {
vertical-align: middle;
}
.input-with-label > input {
margin: 0;
}
.input-with-label > select {
margin: 0;
}
.input-with-label > input[type=text] {
margin: 0;
}
| > > > > | 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
}
.font-size-175 {
font-size: 175%;
}
.font-size-200 {
font-size: 200%;
}
//////////////////////////////////////////////////////////////////
// .input-with-label is intended to be a wrapper element which
// contains a SPAN label and an INPUT control.
.input-with-label {
border: 1px inset #808080;
border-radius: 0.5em;
padding: 0.25em 0.4em;
margin: 0 0.5em;
display: inline-block;
cursor: default;
}
.input-with-label > * {
vertical-align: middle;
}
.input-with-label > input {
margin: 0;
}
.input-with-label > button {
margin: 0;
}
.input-with-label > select {
margin: 0;
}
.input-with-label > input[type=text] {
margin: 0;
}
|
| ︙ | ︙ | |||
1162 1163 1164 1165 1166 1167 1168 |
vertical-align: sub;
}
.input-with-label > label {
font-weight: initial;
margin: 0 0.25em 0 0.25em;
vertical-align: middle;
}
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
vertical-align: sub;
}
.input-with-label > label {
font-weight: initial;
margin: 0 0.25em 0 0.25em;
vertical-align: middle;
}
////////////////////////////////////////////////////////////
// Styles for /fileedit:
// body.fileedit => /fileedit page
body.fileedit .error {
padding: 0.25em;
}
body.fileedit .warning {
padding: 0.25em;
}
body.fileedit textarea {
font-family: monospace;
width: 100%;
flex: 10 1 auto;
height: initial;
}
body.fileedit fieldset {
margin: 0.5em 0 0.5em 0;
padding: 0.25em 0;
border-radius: 0.5em;
border-color: inherit;
border-width: 1px;
font-size: 90%;
overflow: auto;
}
body.fileedit fieldset > legend {
margin: 0 0 0 1em;
padding: 0 0.5em 0 0.5em;
}
body.fileedit fieldset > div {
margin: 0 0.25em 0 0.25em;
padding: 0;
overflow: auto;
}
body.fileedit fieldset > div > .input-with-label {
margin: 0.25em 0.5em;
}
body.fileedit fieldset > div > button {
margin: 0.25em 0.5em;
}
body.fileedit .fileedit-hint {
font-size: 80%;
opacity: 0.75;
}
body.fileedit .fileedit-error-report {
background: yellow;
color: darkred;
margin: 1em 0;
padding: 0.5em;
border-radius: 0.5em;
}
body.fileedit code.fileedit-manifest {
display: block;
height: 16em;
overflow: auto;
white-space: pre;
}
body.fileedit div.fileedit-preview {
margin: 0;
padding: 0;
}
body.fileedit #fileedit-tab-diff-wrapper {
margin: 0;
padding: 0;
overflow: auto;
}
body.fileedit #fileedit-tab-preview-wrapper {
overflow: auto;
}
body.fileedit .fileedit-options.commit-message > div {
display: flex;
flex-direction: column;
justify-content: stretch;
font-family: monospace;
}
body.fileedit .fileedit-options.commit-message > div > * {
margin: 0.25em;
}
body.fileedit #fileedit-commit-button-wrapper {
margin: 0.25em;
}
body.fileedit .tab-container > .tabs > .tab-panel > .fileedit-options {
margin-top: 0;
border: none;
border-radius: 0;
border-bottom-width: 1px;
border-bottom-style: dotted;
}
body.fileedit .tab-container > .tabs > .tab-panel > .fileedit-options > button {
vertical-align: middle;
margin: 0.5em;
}
body.fileedit .tab-container > .tabs > .tab-panel > .fileedit-options > input {
vertical-align: middle;
margin: 0.5em;
}
body.fileedit .tab-container > .tabs > .tab-panel > .fileedit-options > .input-with-label {
vertical-align: middle;
margin: 0.5em;
}
body.fileedit .fileedit-options > div > * {
margin: 0.25em;
}
body.fileedit .fileedit-options.flex-container.flex-row {
align-items: first baseline;
}
body.fileedit #fileedit-file-selector {
display: flex;
flex-direction: column;
align-content: flex-start;
border-color: inherit;
border-width: 1px;
border-style: inset;
border-radius: 0.5em;
padding: 0 0.25em;
margin: 0;
min-height: 12em;
}
body.fileedit #fileedit-file-selector select {
margin: 0 0 0.5em 0;
height: initial;
font-family: monospace;
}
body.fileedit select:focus {
border: none;
}
body.fileedit option:focus {
border: none;
}
body.fileedit #fileedit-file-selector > div {
padding: 0;
margin: 0;
}
body.fileedit #fileedit-file-selector > div > * {
margin: 0.25em 0.5em 0.25em 0;
}
body.fileedit #fileedit-stash-selector {
border-bottom-width: 1px;
border-bottom-style: dotted;
margin: 0.25em;
}
body.fileedit #fileedit-stash-selector select {
margin: 0;
height: initial;
font-family: monospace;
}
|
Changes to src/fileedit.c.
| ︙ | ︙ | |||
1816 1817 1818 1819 1820 1821 1822 |
{
CX("<div id='fileedit-tab-content' "
"data-tab-parent='fileedit-tabs' "
"data-tab-label='File Content'"
">");
CX("<div class='fileedit-options "
"flex-container flex-row child-gap-small'>");
| < < < < < < | | | | | | < | 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 |
{
CX("<div id='fileedit-tab-content' "
"data-tab-parent='fileedit-tabs' "
"data-tab-label='File Content'"
">");
CX("<div class='fileedit-options "
"flex-container flex-row child-gap-small'>");
CX("<button class='fileedit-content-reload confirmer' "
"title='Reload the file from the server, discarding "
"any local edits. To help avoid accidental loss of "
"edits, it requires confirmation (a second click) within "
"a few seconds or it will not reload.'"
">Discard & Reload</button>");
style_select_list_int("select-font-size",
"editor_font_size", "Editor font size",
NULL/*tooltip*/,
100,
"100%", 100, "125%", 125,
"150%", 150, "175%", 175,
"200%", 200, NULL);
|
| ︙ | ︙ | |||
2087 2088 2089 2090 2091 2092 2093 |
CX("<li>\"Delta manifests\" (see the checkbox on the Commit tab) "
"make for smaller commit records, especially in repositories "
"with many files.</li>");
CX("<li>The file selector allows, for usability's sake, only files "
"in leaf checkins to be selected, but files may be edited via "
"non-leaf checkins by passing them as the <code>filename</code> "
"and <code>checkin</code> URL arguments to this page.</li>");
| | < | | 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 |
CX("<li>\"Delta manifests\" (see the checkbox on the Commit tab) "
"make for smaller commit records, especially in repositories "
"with many files.</li>");
CX("<li>The file selector allows, for usability's sake, only files "
"in leaf checkins to be selected, but files may be edited via "
"non-leaf checkins by passing them as the <code>filename</code> "
"and <code>checkin</code> URL arguments to this page.</li>");
CX("<li>The editor \"stashes\" some number of local edits in "
"one of <code>window.fileStorage</code> or "
"<code>window.sessionStorage</code>, if able, but which storage "
"is unspecified and may differ across environments. When saving "
"or force-reloading a file, stashed edits to that version are "
"discarded.</li>");
CX("</ul>");
}
CX("</div>"/*#fileedit-tab-help*/);
|
| ︙ | ︙ |
Changes to src/fossil.bootstrap.js.
| ︙ | ︙ | |||
151 152 153 154 155 156 157 |
return rc;
};
/**
Expects to be passed as hash code as its first argument. It
returns a "shortened" form of hash, with a length which depends
on the 2nd argument: truthy = fossil.config.hashDigitsUrl, falsy
| | > | > > | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
return rc;
};
/**
Expects to be passed as hash code as its first argument. It
returns a "shortened" form of hash, with a length which depends
on the 2nd argument: truthy = fossil.config.hashDigitsUrl, falsy
= fossil.config.hashDigits, number == that many digits. The
fossil.config values are derived from the 'hash-digits'
repo-level config setting or the
FOSSIL_HASH_DIGITS_URL/FOSSIL_HASH_DIGITS compile-time options.
If its first arugment is a non-string, that value is returned
as-is.
*/
F.hashDigits = function(hash,forUrl){
const n = ('number'===typeof forUrl)
? forUrl : F.config[forUrl ? 'hashDigitsUrl' : 'hashDigits'];
return ('string'==typeof hash ? hash.substr(
0, n
) : hash);
};
/**
Sets up pseudo-automatic content preview handling between a
source element (typically a TEXTAREA) and a target rendering
element (typically a DIV). The selector argument must be one of:
|
| ︙ | ︙ | |||
272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
(r)=>eTo[asText ? 'textContent' : 'innerHTML'] = r||''
);
}, false
);
});
return this;
};
/**
Adds a listener for fossil-level custom events. Events are
delivered to their callbacks as CustomEvent objects with a
'detail' property holding the event's app-level data.
The exact events fired differ by page, and not all pages trigger
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
(r)=>eTo[asText ? 'textContent' : 'innerHTML'] = r||''
);
}, false
);
});
return this;
};
/**
Convenience wrapper which adds an onload event listener to the
window object. Returns this.
*/
F.onPageLoad = function(callback){
window.addEventListener('load', callback, false);
return this;
};
/**
Assuming name is a repo-style filename, this function returns
a shortened form of that name:
.../LastDirectoryPart/FilenamePart
If the name has 0-1 directory parts, it is returned as-is.
Design note: in practice it is generally not helpful to elide the
*last* directory part because embedded docs (in particular) often
include x/y/index.md and x/z/index.md, both of which would be
shortened to something like x/.../index.md.
*/
F.shortenFilename = function(name){
const a = name.split('/');
if(a.length<=2) return name;
while(a.length>2) a.shift();
return '.../'+a.join('/');
};
/**
Adds a listener for fossil-level custom events. Events are
delivered to their callbacks as CustomEvent objects with a
'detail' property holding the event's app-level data.
The exact events fired differ by page, and not all pages trigger
|
| ︙ | ︙ |
Changes to src/fossil.page.fileedit.js.
1 2 3 4 |
(function(F/*the fossil object*/){
"use strict";
/**
Code for the /filepage app. Requires that the fossil JS
| | > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
(function(F/*the fossil object*/){
"use strict";
/**
Code for the /filepage app. Requires that the fossil JS
bootstrapping is complete and that several fossil JS APIs have
been installed: fossil.fetch, fossil.dom, fossil.tabs,
fossil.storage, fossil.confirmer.
Custom events, handled via fossil.page.addEventListener():
- Event 'fileedit-file-loaded': passes on information when it
loads a file, in the form of an object:
{
|
| ︙ | ︙ | |||
56 57 58 59 60 61 62 63 64 65 |
}
);
*/
const E = (s)=>document.querySelector(s),
D = F.dom,
P = F.page;
/**
Widget for the checkin/file selection list.
*/
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | > | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
}
);
*/
const E = (s)=>document.querySelector(s),
D = F.dom,
P = F.page;
P.config = {
defaultMaxStashSize: 7
};
/**
$stash is an internal-use-only object for managing "stashed"
local edits, to help avoid that users accidentally lose content
by switching tabs or following links or some such. The basic
theory of operation is...
All "stashed" state is stored using fossil.storage.
- When the current file content is modified by the user, the
current stathe of the current P.finfo and its the content
is stashed. For the built-in editor widget, "changes" is
notified via a 'change' event. For a client-side custom
widget, the client needs to call P.stashContentChange() when
their widget triggers the equivalent of a 'change' event.
- For certain non-content updates (as of this writing, only the
is-executable checkbox), only the P.finfo stash entry is
updated, not the content (unless the content has not yet been
stashed, in which case it is also stashed so that the stash
always has matching pairs of finfo/content).
- When saving, the stashed entry for the previous version is removed
from the stash.
- When "loading", we use any stashed state for the given
checkin/file combination. When forcing a re-load of content,
any stashed entry for that combination is removed from the
stash.
- Every time P.stashContentChange() updates the stash, it is
pruned to $stash.prune.defaultMaxCount most-recently-updated
entries.
- This API often refers to "finfo objects." Those are objects
with a minimum of {checkin,filename} properties (which must be
valid), and a combination of those two properties is used as
basis for the stash keys for any given checkin/filename
combination.
The structure of the stash is a bit convoluted for efficiency's
sake: we store a map of file info (finfo) objects separately from
those files' contents because otherwise we would be required to
JSONize/de-JSONize the file content when stashing/restoring it,
and that would be horribly inefficient (meaning "battery-consuming"
on mobile devices).
*/
const $stash = {
keys: {
index: F.page.name+':index'
},
/**
index: {
"CHECKIN_HASH:FILENAME": {file info w/o content}
...
}
In F.storage we...
- Store this.index under the key this.keys.index.
- Store each file's content under the key
(P.name+'/CHECKIN_HASH:FILENAME'). These are stored separately
from the index entries to avoid having to JSONize/de-JSONize
the content. The assumption/hope is that the browser can store
those records "directly," without any intermediary
encoding/decoding going on.
*/
indexKey: function(finfo){return finfo.checkin+':'+finfo.filename},
/** Returns the key for storing content for the given key suffix,
by prepending P.name to suffix. */
contentKey: function(suffix){return P.name+'/'+suffix},
/** Returns the index object, fetching it from the stash or creating
it anew on the first call. */
getIndex: function(){
if(!this.index) this.index = F.storage.getJSON(this.keys.index,{});
return this.index;
},
_fireStashEvent: function(){
if(this._disableNextEvent) delete this._disableNextEvent;
else F.page.dispatchEvent('fileedit-stash-updated', this);
},
/**
Returns the stashed version, if any, for the given finfo object.
*/
getFinfo: function(finfo){
const ndx = this.getIndex();
return ndx[this.indexKey(finfo)];
},
/** Serializes this object's index to F.storage. Returns this. */
storeIndex: function(){
if(this.index) F.storage.setJSON(this.keys.index,this.index);
return this;
},
/** Updates the stash record for the given finfo
and (optionally) content. If passed 1 arg, only
the finfo stash is updated, else both the finfo
and its contents are (re-)stashed. Returns this.
*/
updateFile: function(finfo,content){
const ndx = this.getIndex(),
key = this.indexKey(finfo),
old = ndx[key];
const record = old || (ndx[key]={
checkin: finfo.checkin,
filename: finfo.filename,
mimetype: finfo.mimetype
});
record.isExe = !!finfo.isExe;
record.stashTime = new Date().getTime();
this.storeIndex();
if(arguments.length>1){
F.storage.set(this.contentKey(key), content);
}
this._fireStashEvent();
return this;
},
/**
Returns the stashed content, if any, for the given finfo
object.
*/
stashedContent: function(finfo){
return F.storage.get(this.contentKey(this.indexKey(finfo)));
},
/** Returns true if we have stashed content for the given finfo
record. */
hasStashedContent: function(finfo){
return F.storage.contains(this.contentKey(this.indexKey(finfo)));
},
/** Unstashes the given finfo record and its content.
Returns this. */
unstash: function(finfo){
const ndx = this.getIndex(),
key = this.indexKey(finfo);
delete finfo.stashTime;
delete ndx[key];
F.storage.remove(this.contentKey(key));
this.storeIndex();
this._fireStashEvent();
return this;
},
/**
Clears all $stash entries from F.storage. Returns this.
*/
clear: function(){
const ndx = this.getIndex(),
self = this;
let count = 0;
Object.keys(ndx).forEach(function(k){
++count;
const e = ndx[k];
delete ndx[k];
F.storage.remove(self.contentKey(k));
});
F.storage.remove(this.keys.index);
delete this.index;
if(count) this._fireStashEvent();
return this;
},
/**
Removes all but the maxCount most-recently-updated stash
entries, where maxCount defaults to this.prune.defaultMaxCount.
*/
prune: function f(maxCount){
const ndx = this.getIndex();
const li = [];
if(!maxCount || maxCount<0) maxCount = f.defaultMaxCount;
Object.keys(ndx).forEach((k)=>li.push(ndx[k]));
li.sort((l,r)=>l.stashTime - r.stashTime);
let n = 0;
while(li.length>maxCount){
++n;
const e = li.shift();
this._disableNextEvent = true;
this.unstash(e);
console.warn("Pruned oldest stash entry:",e);
}
if(n) this._fireStashEvent();
}
};
$stash.prune.defaultMaxCount = P.config.defaultMaxStashSize;
/**
Widget for the checkin/file selection list.
*/
P.fileSelectWidget = {
e:{
container: E('#fileedit-file-selector')
},
finfo: {},
cache: {
checkins: undefined,
files:{},
branchNames: {}
},
/**
Fetches the list of leaf checkins from the server and updates
the UI with that list.
*/
loadLeaves: function(){
D.append(D.clearElement(
|
| ︙ | ︙ | |||
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
D.append(D.clearElement(self.e.ciListLabel),
"Open leaves (newest first):");
self.cache.checkins = list;
D.clearElement(D.enable(self.e.selectCi));
let loadThisOne;
list.forEach(function(o,n){
if(!n) loadThisOne = o;
D.option(self.e.selectCi, o.checkin,
o.timestamp+' ['+o.branch+']: '
+F.hashDigits(o.checkin));
});
self.loadFiles(loadThisOne ? loadThisOne.checkin : false);
}
});
| > | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
D.append(D.clearElement(self.e.ciListLabel),
"Open leaves (newest first):");
self.cache.checkins = list;
D.clearElement(D.enable(self.e.selectCi));
let loadThisOne;
list.forEach(function(o,n){
if(!n) loadThisOne = o;
self.cache.branchNames[F.hashDigits(o.checkin)] = o.branch;
D.option(self.e.selectCi, o.checkin,
o.timestamp+' ['+o.branch+']: '
+F.hashDigits(o.checkin));
});
self.loadFiles(loadThisOne ? loadThisOne.checkin : false);
}
});
|
| ︙ | ︙ | |||
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
F.fetch('fileedit',{
urlParams:{ajax:'filelist', checkin: ciUuid},
responseType: 'json',
onload
});
return this;
},
/**
Initializes the checkin/file selector widget. Must only be
called once.
*/
init: function(){
const selCi = this.e.selectCi = D.select(),
selFiles = this.e.selectFiles
| > > > > > > > > > > | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
F.fetch('fileedit',{
urlParams:{ajax:'filelist', checkin: ciUuid},
responseType: 'json',
onload
});
return this;
},
/**
If this object has ever loaded the given checkin version via
loadLeaves(), this returns the branch name associated with that
version, else returns undefined;
*/
checkinBranchName: function(uuid){
return this.cache.branchNames[F.hashDigits(uuid)];
},
/**
Initializes the checkin/file selector widget. Must only be
called once.
*/
init: function(){
const selCi = this.e.selectCi = D.select(),
selFiles = this.e.selectFiles
|
| ︙ | ︙ | |||
204 205 206 207 208 209 210 |
}, false
);
btnReload.addEventListener(
'click', (e)=>this.loadLeaves(), false
);
delete this.init;
}
| | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
}, false
);
btnReload.addEventListener(
'click', (e)=>this.loadLeaves(), false
);
delete this.init;
}
}/*P.fileSelectWidget*/;
/**
Widget for listing and selecting $stash entries.
*/
P.stashWidget = {
e:{/*DOM element(s)*/},
init: function(domInsertPoint/*insert widget BEFORE this element*/){
const flow = D.addClass(D.div(), 'flex-container','flex-column');
const wrapper = D.addClass(
D.attr(D.div(),'id','fileedit-stash-selector'),
'input-with-label'
);
const sel = this.e.select = D.select();
const btnClear = this.e.btnClear
= D.addClass(D.button("Clear"),'hidden');
D.append(flow, wrapper);
D.append(wrapper, "Local edits ("+(F.storage.storageImplName())+"):",
sel, btnClear);
D.attr(wrapper, "title", [
'Locally "stashed" edits. Timestamps are the last local edit time.',
'Only the',P.config.defaultMaxStashSize,'most recent checkin/file',
'combinations are retained.',
'Committing or reloading a file removes it from this stash.'
].join(' '));
D.option(D.disable(sel), "(empty)");
F.page.addEventListener('fileedit-stash-updated',(e)=>this.updateList(e.detail));
F.page.addEventListener('fileedit-file-loaded',(e)=>this.updateList($stash, e.detail));
sel.addEventListener('change',function(e){
const opt = this.selectedOptions[0];
if(opt && opt._finfo) P.loadFile(opt._finfo);
});
F.confirmer(btnClear, {
confirmText: "REALLY delete ALL local edits?",
onconfirm: (e)=>P.clearStash().loadFile(/*in case P.finfo() was in the stash*/),
ticks: 3
});
if(F.storage.isTransient()){/*Warn if transient storage is in use...*/
D.append(flow, D.append(D.addClass(D.div(),'warning'),
"Warning: persistent storage is not avaible, "+
"so uncomitted edits will not survive a page reload.")
);
}
domInsertPoint.parentNode.insertBefore(flow, domInsertPoint);
$stash._fireStashEvent(/*update this object with the load-time stash*/);
delete this.init;
},
/**
Regenerates the edit selection list.
*/
updateList: function f(stasher,theFinfo){
if(!f.compare){
const cmpBase = (l,r)=>l<r ? -1 : (l===r ? 0 : 1);
f.compare = function(l,r){
const cmp = cmpBase(l.filename, r.filename);
return cmp ? cmp : cmpBase(l.checkin, r.checkin);
};
f.rxZ = /\.\d+Z$/ /* ms and 'Z' part of date string */;
const pad=(x)=>(''+x).length>1 ? x : '0'+x;
f.timestring = function ff(d){
return [
d.getFullYear(),'-',pad(d.getMonth()+1/*sigh*/),'-',pad(d.getDate()),
'@',pad(d.getHours()),':',pad(d.getMinutes())
].join('');
};
}
const index = stasher.getIndex(), ilist = [];
Object.keys(index).forEach((finfo)=>{
ilist.push(index[finfo]);
});
const self = this;
D.clearElement(this.e.select);
if(0===ilist.length){
D.addClass(this.e.btnClear, 'hidden');
D.option(D.disable(this.e.select),"No local edits");
return;
}
D.enable(this.e.select);
D.removeClass(this.e.btnClear, 'hidden');
D.disable(D.option(this.e.select,0,"Select a local edit..."));
const currentFinfo = theFinfo || P.finfo || {};
ilist.sort(f.compare).forEach(function(finfo,n){
const key = stasher.indexKey(finfo),
branch = P.fileSelectWidget.checkinBranchName(finfo.checkin);
const opt = D.option(
self.e.select, n+1/*value is (almost) irrelevant*/,
[F.hashDigits(finfo.checkin, 6), branch,
f.timestring(new Date(finfo.stashTime)),
false ? finfo.filename : F.shortenFilename(finfo.filename)
].join(' ')
);
opt._finfo = finfo;
if(0===f.compare(currentFinfo, finfo)){
D.attr(opt, 'selected', true);
}
});
}
}/*P.stashWidget*/;
/**
Internal workaround to select the current preview mode
and fire a change event if the value actually changes
or if forceEvent is truthy.
*/
P.selectPreviewMode = function(modeValue, forceEvent){
const s = this.e.selectPreviewMode;
if(!modeValue) modeValue = s.value;
else if(s.value != modeValue){
s.value = modeValue;
forceEvent = true;
}
if(forceEvent){
// Force UI update
s.dispatchEvent(new Event('change',{target:s}));
}
};
F.onPageLoad(function() {
P.base = {tag: E('base')};
P.base.originalHref = P.base.tag.href;
P.tabs = new fossil.TabManager('#fileedit-tabs');
P.e = {
taEditor: E('#fileedit-content-editor'),
taCommentSmall: E('#fileedit-comment'),
taCommentBig: E('#fileedit-comment-big'),
|
| ︙ | ︙ | |||
256 257 258 259 260 261 262 |
tabs:{
content: E('#fileedit-tab-content'),
preview: E('#fileedit-tab-preview'),
diff: E('#fileedit-tab-diff'),
commit: E('#fileedit-tab-commit')
}
};
| < | 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
tabs:{
content: E('#fileedit-tab-content'),
preview: E('#fileedit-tab-preview'),
diff: E('#fileedit-tab-diff'),
commit: E('#fileedit-tab-commit')
}
};
/* Figure out which comment editor to show by default and
hide the other one. By default we take the one which does
not have the 'hidden' CSS class. If neither do, we default
to single-line mode. */
if(D.hasClass(P.e.taCommentSmall, 'hidden')){
P.e.taComment = P.e.taCommentBig;
}else if(D.hasClass(P.e.taCommentBig,'hidden')){
|
| ︙ | ︙ | |||
382 383 384 385 386 387 388 |
P.addEventListener(
// Clear diff/preview when new content is loaded/set
'fileedit-content-replaced',
()=>D.clearElement(P.e.diffTarget, P.e.previewTarget)
);
| < < | < < < < < < < < < < < < < < | < > | 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
P.addEventListener(
// Clear diff/preview when new content is loaded/set
'fileedit-content-replaced',
()=>D.clearElement(P.e.diffTarget, P.e.previewTarget)
);
P.fileSelectWidget.init();
P.stashWidget.init(P.e.tabs.content.lastElementChild);
}/*F.onPageLoad()*/);
/**
Getter (if called with no args) or setter (if passed an arg) for
the current file content.
The setter form sets the content, dispatches a
'fileedit-content-replaced' event, and returns this object.
|
| ︙ | ︙ | |||
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
Returns this object, noting that the load is async. After loading
it triggers a 'fileedit-file-loaded' event, passing it
this.finfo.
*/
P.loadFile = function(file,rev){
if(0===arguments.length){
if(!affirmHasFile()) return this;
file = this.finfo.filename;
rev = this.finfo.checkin;
}
const self = this;
const onload = (r,headers)=>{
delete self.finfo;
self.updateVersion({
filename: file,
checkin: rev,
| > > > > > > | 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 |
Returns this object, noting that the load is async. After loading
it triggers a 'fileedit-file-loaded' event, passing it
this.finfo.
*/
P.loadFile = function(file,rev){
if(0===arguments.length){
/* Reload from this.finfo */
if(!affirmHasFile()) return this;
file = this.finfo.filename;
rev = this.finfo.checkin;
}else if(1===arguments.length){
/* Assume finfo-like object */
const arg = arguments[0];
file = arg.filename;
rev = arg.checkin;
}
const self = this;
const onload = (r,headers)=>{
delete self.finfo;
self.updateVersion({
filename: file,
checkin: rev,
|
| ︙ | ︙ | |||
794 795 796 797 798 799 800 |
cbDryRun.checked = true;
}
self.unstashContent(oldFinfo);
delete c.manifest;
self.finfo = c;
self.e.taComment.value = '';
self.updateVersion();
| | | 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 |
cbDryRun.checked = true;
}
self.unstashContent(oldFinfo);
delete c.manifest;
self.finfo = c;
self.e.taComment.value = '';
self.updateVersion();
self.fileSelectWidget.loadLeaves();
}
F.message.apply(F, msg);
self.tabs.switchToTab(self.e.tabs.commit);
};
}
const fd = new FormData();
fd.append('filename',filename);
|
| ︙ | ︙ | |||
841 842 843 844 845 846 847 |
payload: fd,
responseType: 'json',
onload: f.onload
});
return this;
};
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 |
payload: fd,
responseType: 'json',
onload: f.onload
});
return this;
};
/**
Updates P.finfo for certain state and stashes P.finfo, with the
current content fetched via P.fileContent().
If passed truthy AND the stash already has stashed content for
the current file, only the stashed finfo record is updated, else
both the finfo and content are updated.
|
| ︙ | ︙ | |||
1068 1069 1070 1071 1072 1073 1074 |
If a stashed version of the given finfo object exists (same
filename/checkin values), return it, else return undefined.
*/
P.getStashedFinfo = function(finfo){
return $stash.getFinfo(finfo);
};
| < < | 1186 1187 1188 1189 1190 1191 1192 1193 |
If a stashed version of the given finfo object exists (same
filename/checkin values), return it, else return undefined.
*/
P.getStashedFinfo = function(finfo){
return $stash.getFinfo(finfo);
};
})(window.fossil);
|
Changes to www/fileedit-page.md.
| ︙ | ︙ | |||
83 84 85 86 87 88 89 | `/fileedit` will, if possible, store them in `window.fileStorage` or `window.sessionStorage`, if available, but... - Which storage is used is unspecified and may differ across environments. - If neither of those is available, the storage is transient and will not survive a page reload. | | > | | | | | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | `/fileedit` will, if possible, store them in `window.fileStorage` or `window.sessionStorage`, if available, but... - Which storage is used is unspecified and may differ across environments. - If neither of those is available, the storage is transient and will not survive a page reload. - It stores only the most recent checkin/file combinations which have been modified (exactly how many may differ - the number will be noted somewhere in the UI). Note that changing the "executable bit" is counted as a modification, but the checkin comment is not stored separately for each file. If the limit is exceeded, it silently discards the oldest edits. Exactly how long `fileStorage` will survive, and how much it or `sessionStorage` can hold, is environment-dependent. `sessionStorage` will survive until the current browser tab is closed, but it survives across reloads of the same tab. If `/filepage` determines that no peristent storage is available a |
| ︙ | ︙ |