Copied to clipboard

Flag this post as spam?

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


  • David Berglund 7 posts 77 karma points
    Sep 25, 2017 @ 11:58
    David Berglund
    0

    Simple multiplication

    I've created a document type called Project and have among other things added two numeric properties called Rate per hour and Estimated hours. So far so good. But I now I want to multiplicate the content of these properties and output the result in the document type. I realise that I probably need to add another property to do the math and the output. What's the easiest way to accomplish this? For such an easy equation as {{hours}}*[[rate}} it seems overly complicated to need to add both a manifest, controller and view files.

  • Markus Johansson 1930 posts 5858 karma points MVP 2x c-trib
    Sep 25, 2017 @ 20:34
    Markus Johansson
    0

    Hi David!

    From the brakets that you had in your example I'm guessing that you are talking about a AngularJS-view?

    In that case this should work: {{hours * rate}}

    Or you could use a method on your scope, something like {{amount()}}

    And then:

    $scope.amount = function{
       return $scope.hours * $scope.rate;
    }
    
  • David Berglund 7 posts 77 karma points
    Sep 26, 2017 @ 05:02
    David Berglund
    0

    Thanks for your reply. Actually the brackets were more to illustrate the simplicity of what I needed to do. More likely I'd like to paste code like: @{ var result = hours*rate; }

    Profit: @result

    How can I paste code like this in the document type view? Is the only way to create a new property?

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Sep 26, 2017 @ 01:36
    Nathan Woulfe
    0

    Personally I'd create an editor to store both values and output the calculated product - you'd then have hours and rate both in the same scope, rather than having to fetch them from other properties.

  • David Berglund 7 posts 77 karma points
    Sep 26, 2017 @ 05:25
    David Berglund
    0

    Thanks for your reply. I'm aware of this possibility, but then we're back to having to create both manifest, controller and view files. Something that seems overly complicated just to be able to insert basically one line of code. For a system that otherwise is so flexible in building the tabs of the document types it seems crazy that there wouldn't be an easier way to implement custom code.

  • Markus Johansson 1930 posts 5858 karma points MVP 2x c-trib
    Sep 26, 2017 @ 06:55
    Markus Johansson
    0

    Hi!

    Ahh, are you looking to do the calculation in the accual content type (aka document type) edit view?

    Then you only option is a custom property editor - I would not say that this is hard just 3 file and 10-15 lines of code.

    // m

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Sep 26, 2017 @ 07:23
    Nathan Woulfe
    0

    I take your point, but you'll find that adding your own packages makes Umbraco even more flexible - for the sake of a couple of files, you can build out custom editors really easily.

    Also gives you the scope to extend the output in future. For your example, there might be a future need to include currency conversions (strange example, I know), which would be easy to implement inside your custom editor.

  • David Berglund 7 posts 77 karma points
    Sep 26, 2017 @ 07:28
    David Berglund
    0

    Correct. I'm pretty new to Umbraco so my description might not have been clear on that. Still, I would have expected a simpler way. For example a standardised custom code property into which you could insert the lines of code. I guess I have to get more familiar with creating own packages. Thanks!

  • David Berglund 7 posts 77 karma points
    Sep 26, 2017 @ 07:45
    David Berglund
    0

    OK, perhaps I just need to get more familiar with creating my own packages. But let's extend my example. Let's say I have a document type called Customer and a document type called Events. I want to use the Umbraco admin as the primary work surface, instead of a frontend. So in the document type edit view for Customer I want to have a calendar listing instances of Events. Should I build the calendar as a new property as well, or is there a better way considering it will have dependencies from external files (ie jQuery UI)?

  • Markus Johansson 1930 posts 5858 karma points MVP 2x c-trib
    Sep 26, 2017 @ 08:21
    Markus Johansson
    1

    Hi David!

    It's great that you have found Umbraco =D

    I really don't understand why you would want to summeries the rate and hours in the document type editor?

    I would think that this is something you would like to do in the accual edit-view for the node in the content section?

    A property editor is quite simple to create, you can use this as a starting point: https://github.com/enkelmedia/Umbraco7-SeoVisualizer

    If you would like to kickstart your work with Umbraco I can recommend my official Umbrac-courses in Swedish: http://www.enkelmedia.se/vi-erbjuder/utbildning-umbraco.aspx

    For this task "Extending the backoffice" would be the right course.

  • David Berglund 7 posts 77 karma points
    Sep 27, 2017 @ 09:29
    David Berglund
    0

    Thanks to the replies Markus and Nathan. I followed Nathan's advice and stored the values for Hours and Rate in the same editor, making it easy to execute and print the result of the equation within the same scope. My document type Customer, with the tab Projects, containing nested content of the document type Project now looks like this: enter image description here

    Thanks again!

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Sep 27, 2017 @ 09:55
    Nathan Woulfe
    1

    Looks great, nice job.

    I'm a huge fan of building custom editors, even for simpler tasks - anything that makes life easier for content editors is worth doing, in my opinion.

  • Markus Johansson 1930 posts 5858 karma points MVP 2x c-trib
    Sep 27, 2017 @ 09:57
    Markus Johansson
    1

    Looks great! I agree with Nathan - custom editors rocks =D

  • Mikael Soerensen 3 posts 93 karma points
    Sep 27, 2017 @ 10:55
    Mikael Soerensen
    0

    Nice one David.

    Im actually doing something similar my self, and i actually got stuck at the same problem as you had :-). Keep up the good work!

    Many Regards

    Mikael S

  • David Berglund 7 posts 77 karma points
    Sep 27, 2017 @ 13:29
    David Berglund
    0

    On to the next thing; building a calendar in the admin, listing posts of a certain document type. Might come another cry for help soon...

Please Sign in or register to post replies

Write your reply to:

Draft