Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • jake williamson 207 posts 872 karma points
    Jan 23, 2022 @ 23:39
    jake williamson
    0

    is it possible to start the editor service file picker in the wwwroot?

    hey out there,

    we've been using the editorService.treePicker to allow users to pick a css file in the backoffice:

    const filePicker = {
        title: "Pick your required css file",
        section: "settings",
        treeAlias: "files",
        entityType: "file",
        isDialog: true,
        filter: function (i) {
            return !(i.name.indexOf(".css") !== -1);
        },
        filterCssClass: "not-allowed",
        select: function (node) {
            const filepath = decodeURIComponent(node.id.replace(/\+/g, " "));
            vm.file = "/" + filepath;
            $scope.model.value = vm.file;
    
            updateModel();
            editorService.close();
        },
        close: function () {
            editorService.close();
        }
    };
    
    editorService.treePicker(filePicker);
    

    however we've hit a snag in that the picker now starts at the root level meaning all our paths start with the 'wwwroot' folder:

    file picker tree picker

    picked result

    now we could replace the wwwroot in the /wwwroot/css/site.min.css path but that seems a little clunky...

    we've had a dig in the core and found that the rte.prevalues.controller.js uses a stylesheetResource to load in the css style sheets for the rich text editor:

    rte stylesheets

    this is kind of an option however has two big issues for us... first, not all sites have the css in a css folder (appreciate this is a requirement for the rte datatype though) and second we also have a file picker for javascript files!

    soooo.... is there a way to get the tree picker to start in the wwwroot folder and omit the path?!

    as ever, any suggestions are greatly received ;)

  • Mark Drake 133 posts 457 karma points c-trib
    Jan 24, 2022 @ 03:38
    Mark Drake
    0

    I forget where, possibly the Block List configuration, where this exact behavior was driving me up a wall. I wanted to pick a CSS file under wwwroot but then the request for that CSS file resulted in a 404.

    This won't directly answer your question but I hope that it gives you at least a temporary reprieve from the frustration.

    I added a redirect to my Startup.cs Configure() method.

    First: add the appropriate using reference if you haven't already.

    using Microsoft.AspNetCore.Rewrite;
    

    Second: add the following code to the Configure() method, preceding app.UseUmbraco()

    // Rewrite rules for wwwroot
    var options = new RewriteOptions()
         .AddRewrite(@"^wwwroot/([\w\W]+)", "$1", skipRemainingRules: true);
    app.UseRewriter(options);
    

    You could also do this with a redirect, which is probably more appropriate.

    // Rewrite rules for wwwroot
    var options = new RewriteOptions()
         .AddRedirect("wwwroot/(.*)", "$1");
    app.UseRewriter(options);
    
  • jake williamson 207 posts 872 karma points
    Jan 24, 2022 @ 08:07
    jake williamson
    0

    hi mark,

    thank you for the suggestion - my only concern is that this adds the rewrite or redirect for the whole site...

    ...the problem being the code in question is going to be in an umbraco plugin so once you install it, it'll mess with the target site which might not be the desired behaviour!

    there's gotta be a way to do it! i've been trying to figure out how the tree pickers work for things like macros etc where you pick an mcv view and it goes directly to the 'views' folder rather than the tree. there's not much in the way of docos so it's a case of trawling the core looking for a similar example...

    either that or it's gonna be roll our own!

    the hunt continues,

    cheers,

    jake

Please Sign in or register to post replies

Write your reply to:

Draft