Fossil

Check-in [371b162ff3]
Login

Check-in [371b162ff3]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The filename/version block on the first fileedit tab is now generated completely dynamically, rather than being filled out with '???' with broken links before a file is loaded.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | fileedit-ajaxify
Files: files | file ages | folders
SHA3-256: 371b162ff38c0b2154efec53a72421aa675436029418c1c3a6a97f9435559050
User & Date: stephan 2020-05-14 03:39:40.058
Context
2020-05-14
03:55
Minor help text, style, and layout tweaks. ... (check-in: 28b2261b75 user: stephan tags: fileedit-ajaxify)
03:39
The filename/version block on the first fileedit tab is now generated completely dynamically, rather than being filled out with '???' with broken links before a file is loaded. ... (check-in: 371b162ff3 user: stephan tags: fileedit-ajaxify)
03:00
fileedit: now gets the file perms via the response header and updates the Is Executable checkbox accordingly. Similary, mimetype is now harvested from the response headers and is used, in place of file extensions, for the "is this a wiki page?" determination. Added fossil-level event infrastructure to allow pages to communicate page-specific events to skin-injected/user-supplied JS code, and fileedit now emits a fileedit-file-loaded event when it loads a new file. Replaced old uses of the term "save" with "commit", per forum feedback. ... (check-in: f1b2e509e7 user: stephan tags: fileedit-ajaxify)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/default_css.txt.
942
943
944
945
946
947
948
949
950
951
952
953
954
955

956
957
958
959
960
961
962
  opacity: 1.0;
  border-top-style: outset;
  border-left-style: outset;
  border-right-style: outset;
}
//////////////////////////////////
// Styles for /fileedit:
textarea.fileedit {
  font-family: monospace;
  width: 100%;
  flex: 10 1 auto;
}
body.fileedit fieldset {
  margin: 0.5em 0 0.5em 0;

  border-radius: 0.5em;
  border-color: inherit;
  border-width: 1px;
  font-size: 85%;
}
body.fileedit fieldset > legend {
  margin: 0 0 0 1em;







|






>







942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
  opacity: 1.0;
  border-top-style: outset;
  border-left-style: outset;
  border-right-style: outset;
}
//////////////////////////////////
// Styles for /fileedit:
body.fileedit textarea {
  font-family: monospace;
  width: 100%;
  flex: 10 1 auto;
}
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: 85%;
}
body.fileedit fieldset > legend {
  margin: 0 0 0 1em;
Changes to src/fileedit.c.
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779

  /***** File/version info tab *****/
  {
    CX("<div id='fileedit-tab-version' "
       "data-tab-parent='fileedit-tabs' "
       "data-tab-label='File Info &amp; Selection'"
       ">");
    CX("File: "
       "<code id='finfo-file-name'>" "???" "</code><br>");
    CX("Checkin Version: "
       "[<a id='timeline-link' href='#'>/timeline</a>] "
       "[<a id='r-link' href='#'>/info</a>] "
       /* %R/info/%!S */
       "<code id='r-label'>" "???" "</code><br>"
       );
    CX("Permalink: <code>"
       "<a id='permalink' href='#'>" "???" "</a></code><br>"
       "(Clicking the permalink will reload the page and discard "
       "all edits!)");

    CX("<h1>Select a file to edit:</h1>");
    CX("<div id='fileedit-file-selector'></div>");
    CX("</div>"/*#fileedit-tab-version*/);
  }
  
  /******* Content tab *******/
  {







|
<
|
<
<
<
<
<
<
<
<
|
|







1753
1754
1755
1756
1757
1758
1759
1760

1761








1762
1763
1764
1765
1766
1767
1768
1769
1770

  /***** File/version info tab *****/
  {
    CX("<div id='fileedit-tab-version' "
       "data-tab-parent='fileedit-tabs' "
       "data-tab-label='File Info &amp; Selection'"
       ">");
    CX("<fieldset id='file-version-details'>"

       "<legend>File/Version</legend>"








       "<div>No file loaded.</div>"
       "</fieldset>");
    CX("<h1>Select a file to edit:</h1>");
    CX("<div id='fileedit-file-selector'></div>");
    CX("</div>"/*#fileedit-tab-version*/);
  }
  
  /******* Content tab *******/
  {
Changes to src/fossil.page.fileedit.js.
206
207
208
209
210
211
212

213
214
215
216
217
218
219
                   +"button.fileedit-content-reload"),
      selectPreviewMode: E('#select-preview-mode select'),
      selectHtmlEmsWrap: E('#select-preview-html-ems'),
      selectEolWrap:  E('#select-preview-html-ems'),
      cbLineNumbersWrap: E('#cb-line-numbers'),
      cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'),
      cbIsExe: E('input[type=checkbox][name=exec_bit]'),

      tabs:{
        content: E('#fileedit-tab-content'),
        preview: E('#fileedit-tab-preview'),
        diff: E('#fileedit-tab-diff'),
        commit: E('#fileedit-tab-commit')
      }
    };







>







206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
                   +"button.fileedit-content-reload"),
      selectPreviewMode: E('#select-preview-mode select'),
      selectHtmlEmsWrap: E('#select-preview-html-ems'),
      selectEolWrap:  E('#select-preview-html-ems'),
      cbLineNumbersWrap: E('#cb-line-numbers'),
      cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'),
      cbIsExe: E('input[type=checkbox][name=exec_bit]'),
      fsFileVersionDetails: E('#file-version-details'),
      tabs:{
        content: E('#fileedit-tab-content'),
        preview: E('#fileedit-tab-preview'),
        diff: E('#fileedit-tab-diff'),
        commit: E('#fileedit-tab-commit')
      }
    };
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
    }
    s.value = c;
    this.e.taComment = s;
    D.addClass(h, 'hidden');
    D.removeClass(s, 'hidden');
    console.debug(s,h);
  };









  
  /**
     updateVersion() updates the filename and version in various UI
     elements...

     Returns this object.
  */
  P.updateVersion = function(file,rev){







    this.finfo = {filename:file,checkin:rev};

    const E = (s)=>document.querySelector(s),
          euc = encodeURIComponent,
          rHuman = F.hashDigits(rev),
          rUrl = F.hashDigits(rev,true);
    D.append(
      D.clearElement(E('#r-label')),
      rHuman
    );
    var e;
    e = E('#timeline-link');
    D.attr(e, 'href',F.repoUrl('timeline',{c:rUrl}));
    e = E('#finfo-file-name');
    D.append(

      D.clearElement(e),
      D.a(F.repoUrl('finfo',{name:file, m:rUrl}), file)

    );

    e = E('#r-link');
    D.attr(e, 'href', F.repoUrl('info/'+rUrl));


    e = E('#r-label');
    D.append(D.clearElement(e),rHuman);




    const purlArgs = F.encodeUrlArgs({
      filename: this.finfo.filename,
      checkin: rUrl
    },false,true);
    const purl = F.repoUrl('fileedit',purlArgs);


    e = E('#permalink');
    D.attr(D.append(D.clearElement(e),'?'+purlArgs),'href', purl);

    return this;
  };

  const affirmHasFile = function(){
    if(!P.finfo) F.error("No file is loaded.");
    return !!P.finfo;
  };

  /**
     loadFile() loads (file,checkinVersion) and updates the relevant
     UI elements to reflect the loaded state. If passed no arguments
     then it re-uses the values from the currently-loaded file
     (becoming a no-op if no file is loaded).

     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){







>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
|
>
|
<


<
|
<
<
<
<
<
<

>
|
|
>

>
|
|
>
>
|
|
>
>
>
>





>
>
|
|
>



<
<
<
<
<



|
|







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
    }
    s.value = c;
    this.e.taComment = s;
    D.addClass(h, 'hidden');
    D.removeClass(s, 'hidden');
    console.debug(s,h);
  };

  /**
     Returns true if fossil.page.finfo is set, indicating that a file
     has been loaded, else it reports an error and returns false.
  */
  const affirmHasFile = function(){
    if(!P.finfo) F.error("No file is loaded.");
    return !!P.finfo;
  };
  
  /**
     updateVersion() updates the filename and version in various UI
     elements...

     Returns this object.
  */
  P.updateVersion = function(file,rev){
    if(1===arguments.length){/*assume object*/
      this.finfo = arguments[0];
      file = this.finfo.filename;
      rev = this.finfo.checkin;
    }else if(0===arguments.length){
      if(!affirmHasFile()) return this;
    }else{
      this.finfo = {filename:file,checkin:rev};
    }
    const eTgt = this.e.fsFileVersionDetails.querySelector('div'),

          rHuman = F.hashDigits(rev),
          rUrl = F.hashDigits(rev,true);

    D.clearElement(eTgt);






    D.append(
      eTgt, "File: ",
      D.append(D.code(),
               D.a(F.repoUrl('finfo',{name:file, m:rUrl}), file)),
      D.br()
    );
    D.append(
      eTgt, "Checkin Version: ",
      D.append(D.code(), D.a(F.repoUrl('info/'+rUrl), rHuman)),
      " [",D.a(F.repoUrl('timeline',{m:rUrl}), "timeline"),"]",
      D.br()
    );
    D.append(
      eTgt, "Mimetype: ",
      D.append(D.code(), this.finfo.mimetype||'???'),
      D.br()
    );
    const purlArgs = F.encodeUrlArgs({
      filename: this.finfo.filename,
      checkin: rUrl
    },false,true);
    const purl = F.repoUrl('fileedit',purlArgs);
    D.append(
      eTgt,
      "Permalink: ",
      D.append(D.code(),D.a(purl,true))
    );
    return this;
  };






  /**
     loadFile() loads (file,checkinVersion) and updates the relevant
     UI elements to reflect the loaded state. If passed no arguments
     then it re-uses the values from the currently-loaded file, reloading
     it (emitting an error message if no file is loaded).

     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){
490
491
492
493
494
495
496
497


498
499

500
501
502
503
504
505
506
        ajax: 'content',
        filename:file,
        checkin:rev
      },
      responseHeaders: ['x-fileedit-file-perm', 'content-type'],
      onload:(r,headers)=>{
        F.message('Loaded content.');
        self.updateVersion(file,rev);


        self.finfo.isExe = ('x'===headers['x-fileedit-file-perm']);
        self.finfo.mimetype = headers['content-type'].split(';').shift();

        self.tabs.switchToTab(self.e.tabs.content);
        self.e.cbIsExe.checked = self.finfo.isExe;
        self.value(r);
        self.dispatchEvent('fileedit-file-loaded', self.finfo);
      }
    });
    return this;







|
>
>
|
|
>







507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
        ajax: 'content',
        filename:file,
        checkin:rev
      },
      responseHeaders: ['x-fileedit-file-perm', 'content-type'],
      onload:(r,headers)=>{
        F.message('Loaded content.');
        self.updateVersion({
          filename: file,
          checkin: rev,
          isExe: ('x'===headers['x-fileedit-file-perm']),
          mimetype: headers['content-type'].split(';').shift()
        });
        self.tabs.switchToTab(self.e.tabs.content);
        self.e.cbIsExe.checked = self.finfo.isExe;
        self.value(r);
        self.dispatchEvent('fileedit-file-loaded', self.finfo);
      }
    });
    return this;
633
634
635
636
637
638
639


640
641
642
643
644
645
646
647
648
649
650
          c.dryRun ? '(dry run)' : '',
          '[', F.hashDigits(c.uuid) ,'].'
        ];
        if(!c.dryRun){
          msg.push('Re-activating dry-run mode.');
          self.e.taComment.value = '';
          cbDryRun.checked = true;


          self.updateVersion(filename, c.uuid);
          self.fileSelector.loadLeaves();
        }
        F.message.apply(fossil, msg);
        self.tabs.switchToTab(self.e.tabs.commit);
      };
    }
    if(!content){
      f.updateView('');
      return this;
    }







>
>
|


|







653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
          c.dryRun ? '(dry run)' : '',
          '[', F.hashDigits(c.uuid) ,'].'
        ];
        if(!c.dryRun){
          msg.push('Re-activating dry-run mode.');
          self.e.taComment.value = '';
          cbDryRun.checked = true;
          self.finfo.filename = filename;
          self.finfo.checkin = c.uuid;
          self.updateVersion();
          self.fileSelector.loadLeaves();
        }
        F.message.apply(F, msg);
        self.tabs.switchToTab(self.e.tabs.commit);
      };
    }
    if(!content){
      f.updateView('');
      return this;
    }