Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Apr 22, 2020 @ 21:38
    Owain Williams
    0

    Custom action on preview button

    Hi I found a skrift article by Dave W that has been really useful so far. I've been able to intercept the preview button in the back office but I'm now have a question which I hope someone can help with as my angular knowledge is rubbish.

    Firstly the article is: https://skrift.io/articles/archive/changing-backoffice-functionality-without-changing-core-code/

    I need to only interept the preview button if I'm using a specific document type and if that matches,I want to make a get request to a controller that I have which creates a pdf on the fly.

    Just now if I call the pdf via a URL, it works so all I need is for the preview button to also load that pdf.

    Can anyone help?

    Thanks

  • Rasmus Eeg 91 posts 457 karma points c-trib
    Apr 23, 2020 @ 07:37
    Rasmus Eeg
    0

    Hi there,

    Why not use the documents templates CSHTML file, and have that respond with a PDF stream?

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Apr 23, 2020 @ 10:20
    Owain Williams
    0

    The issue I have is, on the front end, the only way you can generate a PDF is by going through a number of steps, which creates a JSON object and that is then parsed in to the PDF. When in the backoffice, these steps haven't been carried out and so the JSON object is empty. What I've done is if /umbraco/surface/pdfgenerator/prewiewpdf is hit, then I put my own json in and the PDF works fine.

    The other issue is, the PDF is made up of content from the CMS and content that is within a view. It's hard to explain but basically, I find a node in the backoffice by xpath and I take all the content from that node and pass it to a seperate view. That seperate view now has the CMS'd and non CMS'd content in it but when pressing preview, it doesn't go through that journey as it's only trying to display the node I'm on.

    So when I hit /umbraco/surface/pdfgenerator/prewiewpdf that journey is executed.

    Does that make sense?

  • Rasmus Eeg 91 posts 457 karma points c-trib
    Apr 23, 2020 @ 11:12
    Rasmus Eeg
    0

    Hi Owain,

    Yes it kind of does.

    You can do all the same logic from your view file or a render controller, that is done in your current surface controller.

    You can also call your surface method by creating a new instance of the controller inside your view og render controller.

    What I do in these cases, is creating a new class which does all the business logic. Controllers should have no business logic.

    Construct the new class with dependency injcection for umbraco 8. And using a normal construct for umbraco 7.

    But if you are not up for the refractor. I would recommend you simply redirect from view to surface controller.

    That should work without issues.

    Then the normal preview function should be fine.

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Apr 23, 2020 @ 18:33
    David Brendel
    0

    Hi Owain,

    Not sure what the preview url looks like but shouldn't it contain the ID of the page? With that you could fetch the whole info about it and check the document type. Then call your controller or switch the url.

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Apr 23, 2020 @ 21:24
    Owain Williams
    0

    I'm actually rebuilding this in U8 so can try a couple of options. Yes the URL does have the id of the page, my issue is lack of knowledge on how to do any of this in angular.

    By the sounds of it, it is possible, which is good but if anyone can guide me on how to progress this, I'd really appreciate it.

    As I said, I've been having some success by using the skrift article i.e I can get the URL from the preview button but that's about it so far.

  • Rasmus Eeg 91 posts 457 karma points c-trib
    Apr 24, 2020 @ 07:26
    Rasmus Eeg
    0

    Hi Owain, I'm confused why you want to do it with angular?

    I would recommend doing it using C#

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Apr 24, 2020 @ 10:18
    Owain Williams
    0

    I think the issue is I don't want to preview anything in the backoffice within the usual preview screen. I want to actually hit my PDF generator controller when I click the Preview button. This will then actually generate the PDF and download for the user. To do this, unless Im mistaken, I need to use angular to highjack the preview button

  • Rasmus Eeg 91 posts 457 karma points c-trib
    Apr 24, 2020 @ 10:23
    Rasmus Eeg
    0

    That makes sense, in that case I would use a httpmodule, to hijack the request, and then return your custom PDF stream response.

    Our use your current angular and just link to your controller on click?

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Apr 24, 2020 @ 04:01
    David Brendel
    0

    If I can make some time today I will try if I can come up with something; if nobody else is faster ;)

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Apr 24, 2020 @ 10:18
    Owain Williams
    0

    That would be a massive help David, thank you

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Apr 25, 2020 @ 22:27
    David Brendel
    0

    Hi Owain,

    I had a look and I'm not sure if it is possible to do it in angular. The preview button opens a new windows and then set's the url.

    var previewWindow = $window.open('preview/?init=true', 'umbpreview');
    

    Maybe it is easier to do a HttpModule or so to listen to the url.

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    May 04, 2020 @ 07:40
    Owain Williams
    0

    I'll see if I can get another chance to have a look at this. Been a bit busy on another project for the past week :)

  • Mathew John 13 posts 103 karma points
    Mar 02, 2023 @ 14:41
    Mathew John
    0

    Hi Owain,

    Did you managed to get a solution for this?

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Mar 02, 2023 @ 15:34
    Owain Williams
    0

    Hi Mathew Wow, this was a file ago, I can't even remember what I was trying to do. I think we gave up in the end. Sorry that's not very useful.

    O.

  • Mathew John 13 posts 103 karma points
    Mar 03, 2023 @ 05:16
    Mathew John
    0

    Hi Owain,

    Thanks for your response :)

    I have been looking to give a custom url for preview. Do you think I have to stop here and look for any other work-around? :'(

Please Sign in or register to post replies

Write your reply to:

Draft