Copied to clipboard

Flag this post as spam?

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


  • Peter Cort Larsen 418 posts 1015 karma points
    May 06, 2020 @ 11:12
    Peter Cort Larsen
    0

    Member Data Type Get sql data

    Hi,

    I want to create a data type, that will used in the members section. On each member i want to list data from a sql table thats match the member id.

    How do i go about this task?

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    May 06, 2020 @ 14:18
    Søren Gregersen
    0

    Hi,

    Your question is marked as being for umbraco 7, but just a quick note, that In umbraco 8 you would probably do a content app for this :)

    In v7, it could be done by implementing a property editor. There are multiple ways to do this. A good starting point would be the documentation https://our.umbraco.com/Documentation/Tutorials/Creating-a-Property-Editor/index-v7

    You can find more info/tutorials here: https://24days.in/umbraco-cms/2016/custom-property-editor-tutorial/ https://www.youtube.com/watch?v=FICgnOiwhpY https://www.markadrake.com/custom-umbraco-property-editor-tutorial-character-counts/

    Both content and members share datastructure, so the process is the same for both.

  • Peter Cort Larsen 418 posts 1015 karma points
    May 11, 2020 @ 18:50
    Peter Cort Larsen
    0

    Thanks,

    I am almost there:

    In the JS file, I want to retrieve the URL and get the guid of the member. It works when I view the first member, but when I go the next member I see the previous members' details, until i refresh the page.

    Somehow this part gets cached or something like that:

    var parts = window.location.href.split('/'); var lastSegment = parts.pop() || parts.pop(); /// user guid:/umbraco#/member/member/edit/aeacde7b-ed76-4d71-94bc-83be7b21695d -> aeacde7b-ed76-4d71-94bc-83be7b21695d

        angular.module("umbraco").controller("MemberDownloads", function ($scope, taggedResource) {
        $scope.newTag = '';
        $scope.alltags = [];
    
    
        taggedResource.getTags().then(function (res) {
            var data = res.data;
            for (var tag in data) {
                var name = tag;
                if (data.hasOwnProperty(tag)) {
                    $scope.alltags.push([tag, data[tag]]);
                }
            }
        });
    
    });
    
    angular.module("umbraco.resources").factory("taggedResource", function ($http) {
    
        var taggedService = {};
    
        var parts = window.location.href.split('/');
        var lastSegment = parts.pop() || parts.pop();  // user guid:/umbraco#/member/member/edit/aeacde7b-ed76-4d71-94bc-83be7b21695d -> aeacde7b-ed76-4d71-94bc-83be7b21695d
    
    
        taggedService.getTags = function () {
            return $http.get("/umbraco/surface/MemberDownloads/GetDownloads/" + lastSegment, { timeout: 2000 });
        };
        return taggedService;
    
    });
    
  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    May 11, 2020 @ 18:56
    Søren Gregersen
    100

    Hi,

    In your resource, you only ask for the id once, and then reuse it.

    In angular you get the "taggedResource" injencted, so you need to make it stateless.

    your "getTags"-method should take the member id as a parameter.

    In your controller do:

    var parts = window.location.href.split('/');
    var memberId = parts[parts.length-1];
    taggedResource.getTags(memberId).then(...);
    

    and in your resource:

    taggedService.getTags = function (memberId) {
        return $http.get("/umbraco/surface/MemberDownloads/GetDownloads/" + memberId, { timeout: 2000 });
    };
    

    hth :)

  • Peter Cort Larsen 418 posts 1015 karma points
    May 11, 2020 @ 19:03
    Peter Cort Larsen
    0

    Thanks,

    I just tried that, with no luck.

    I have this:

    angular.module("umbraco").controller("MemberDownloads", function ($scope, taggedResource) {
        $scope.newTag = '';
        $scope.alltags = [];
    
        var parts = window.location.href.split('/');
        var memberId = parts[parts.length - 1];
    
        taggedResource.getTags(memberId).then(function (res) {
            var data = res.data;
            for (var tag in data) {
                var name = tag;
                if (data.hasOwnProperty(tag)) {
                    $scope.alltags.push([tag, data[tag]]);
                }
            }
        });
    });
    
    angular.module("umbraco.resources").factory("taggedResource", function ($http) {
    
        var taggedService = {};
    
        taggedService.getTags = function (memberId) {
            return $http.get("/umbraco/surface/MemberDownloads/GetDownloads/" + memberId, { timeout: 2000 });
        };
        return taggedService;
    
    });
    
  • Peter Cort Larsen 418 posts 1015 karma points
    May 11, 2020 @ 19:05
    Peter Cort Larsen
    1

    jhmm, it works, must have been a cache problem.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    May 11, 2020 @ 19:05
    Søren Gregersen
    0

    it always is ;)

Please Sign in or register to post replies

Write your reply to:

Draft