+ Reply to Thread
Page 14 of 15 FirstFirst ... 4 12 13 14 15 LastLast
Results 131 to 140 of 147

Thread: ANNOUNCE: TSTable() template, sortable/filterable table generator

  1. #131
    Join Date
    Jan 2008
    Location
    Rotterdam, the Netherlands
    Posts
    136

    Default

    Hi Neil, fantastic template! And very good documentation too, since even I got it working. There is one thing I can not find out though, and that is how to reset the links in the template to local files. I did this, but it is obviously not correct:
    var tablesorter_uri = "D:\Program Files\MindTouch\MindTouch\web\scripts\res\jquery\t stable\tstable.tablesorter.min.js";

  2. #132
    Join Date
    Mar 2008
    Posts
    1,630

    Default

    Dadeo:
    What you want to feed to TSTable in this case is a list of page variables; specifically, a list of page variables for pages that link to the current page. Using the API to fetch the <inbound> list is on the right track, but your implementation has sort of gone off into the weeds.

    First let's produce a working solution. Because you're interested in the current page, you can just use the page variable. Wiki.page(page.path) === page. After fetching the API data for the current page, we'll use xml.list() to fetch all the paths of inbound pages. Then we'll use wiki.getpage() to get the page variable for each one, using a list constructor to build it:
    Code:
    var x = wiki.api(page.api);
    var data = [ wiki.getpage(path) foreach var path in xml.list(x,"//inbound//path") ];
    You can now pass that data straight to TSTable. Your last two columns should work fine as-is, but you'll need to re-write the first, keeping in mind that $ is a page variable.

    Foreach syntax can be a bit complex but it is consistent. You've read this article, right?

    Now let's look at the code you posted to see where you went astray:
    1) Putting TSTable *inside* your foreach loop. Unless your goal is to generate a bunch of tables, this is not going to work out well.
    2) Passing the wrong kind of data to TSTable. Xml.text() just outputs a single text string. You want to pass a list of structures to TSTable. Think about what data you want to give to TSTable, and work backwards from there, as I did at the top of this post.
    3) In your TSTable columns, your first column used eval code but doesn't reference $, pretty much guaranteeing bad results. In general, your first column definition doesn't seem to follow the same ground rules as the last two (which are clearly designed to operate on page variables.)

  3. #133
    Join Date
    Mar 2008
    Posts
    1,630

    Default

    Quote Originally Posted by guido View Post
    Hi Neil, fantastic template! And very good documentation too, since even I got it working. There is one thing I can not find out though, and that is how to reset the links in the template to local files. I did this, but it is obviously not correct:
    var tablesorter_uri = "D:\Program Files\MindTouch\MindTouch\web\scripts\res\jquery\t stable\tstable.tablesorter.min.js";
    Well, it needs to be URI, and that is not a URI but rather a Windows file path. I do not have any clue about the directory structure of Mindtouch on Windows. Looking at what you just wrote there, I could speculate that this could work for you:
    Code:
    var tablesorter_uri = "/scripts/res/jquery/tstable/tstable.tablesorter.min.js";
    But that is a guess.

  4. #134
    Join Date
    Jun 2010
    Posts
    85

    Default

    @neilw - thank you SOOO much - I apologize for being such a noob, but I am a content manager with almost no experience in coding/scripts. Also, as our wiki is for an open source app, we all work as volunteers. So, I really shouldn't be attempting such things , but everyone loves our TSTables so much and now I am screwed because they keep asking me to do them!!

    Your solution worked very well with the following code:
    Code:
    var x = wiki.api(page.api);
    var data = [ wiki.getpage(path) foreach var path in xml.list(x,"//inbound//path") ];
    TSTable {
        options: { pager:true, zebra:true, width:"80%", nodata:"No changes yet for this control" },
        columns: [
        { key:"(web.link($.uri,$.title))", title:"Change" },
        { key:"(date.format($.revisions[0].date,'yyyy/MM/dd'))", title:"Date", width:"20%", initial:1 },
        { key:"(var t=$.tags; foreach(var x in t) { var s = string.split(x['name'], ':'); if(s != null && s[0] == 'rel'){ s[1] .. ' '}  })", title:"Release"}
        ],
        data: data
    }
    My only problem now is that I need to constrain the inbound links to subpages of a specific page. How do I do that? If you can even point me in the right direction (link to an relevant MT Wiki page) I can probably figure it out. I assume I want to specify a specific path for "var data = [ wiki.getpage(path) foreach var path in xml.list(x,"//inbound//path") ];" so I tried to add a 'var path = ' statement but either that is the wrong approach or I didn't get the syntax right (as usual!)

    Here are some comments on your guidance/questions so you understand where I get lost.
    Quote Originally Posted by neilw View Post
    You can now pass that data straight to TSTable. Your last two columns should work fine as-is, but you'll need to re-write the first, keeping in mind that $ is a page variable.
    I did understand that, you can see the above example what I normally use. I was just trying anything I could without understanding what I was doing.
    Quote Originally Posted by neilw View Post
    Foreach syntax can be a bit complex but it is consistent. You've read this article, right?
    Several times my comprehension has increased to almost 10% now. I am sure as I learn more, it will increase further.
    Quote Originally Posted by neilw View Post
    Now let's look at the code you posted to see where you went astray:
    1) Putting TSTable *inside* your foreach loop. Unless your goal is to generate a bunch of tables, this is not going to work out well.
    That was just dumb - I missed closing the foreach statement DUH!
    Quote Originally Posted by neilw View Post
    2) Passing the wrong kind of data to TSTable. Xml.text() just outputs a single text string. You want to pass a list of structures to TSTable. Think about what data you want to give to TSTable, and work backwards from there, as I did at the top of this post.
    I was lost trying to figure out the data structures. I normally use wiki.getsearch as your tutorial examples all do. And search I understand! It never occurred to me I could define var data and use that in the data structure. DUH Now it seems obvious and stupid that I did not think of it. Is that mentioned in the tutorial? I guess it is a somewhat 'advanced' option, which most knowledgeable Dekiscript users would grasp anyway.
    Quote Originally Posted by neilw View Post
    3) In your TSTable columns, your first column used eval code but doesn't reference $, pretty much guaranteeing bad results. In general, your first column definition doesn't seem to follow the same ground rules as the last two (which are clearly designed to operate on page variables.)
    Yep as I said above, I do understand the column definitions/keys, I was just trying anything in desperation to see if I could figure out where to process the inbound links.

  5. #135
    Join Date
    Jan 2008
    Location
    Rotterdam, the Netherlands
    Posts
    136

    Default

    Ok, I solved this by uploading the scripts and pictures to the admin 'MyPage' through the web interface, in stead of saving them to a folder on the server. Now my URI reads: http://myserver01/@api/deki/files/21...esorter.min.js

  6. #136
    Join Date
    Mar 2008
    Posts
    1,630

    Default

    Quote Originally Posted by dadeo View Post
    @neilw - thank you SOOO much - I apologize for being such a noob, but I am a content manager with almost no experience in coding/scripts. Also, as our wiki is for an open source app, we all work as volunteers. So, I really shouldn't be attempting such things , but everyone loves our TSTables so much and now I am screwed because they keep asking me to do them!!
    No problem.

    Your solution worked very well with the following code:
    ...
    Yup, that looks perfect.

    My only problem now is that I need to constrain the inbound links to subpages of a specific page. How do I do that? If you can even point me in the right direction (link to an relevant MT Wiki page) I can probably figure it out. I assume I want to specify a specific path for "var data = [ wiki.getpage(path) foreach var path in xml.list(x,"//inbound//path") ];" so I tried to add a 'var path = ' statement but either that is the wrong approach or I didn't get the syntax right (as usual!)
    That's easy enough. What you want is filter the list constructor to only those paths that *start with* a particular path. For that we'll use a "where" clause along with string.startswith():

    Code:
    var inbound_root = "path_of_page_whose_inbound_subpages_should_be_shown" .. "/"; // Must have a single trailing slash!!!!
    var x = wiki.api(page.api);
    var data = [
        wiki.getpage(path)
        foreach var path in xml.list(x,"//inbound//path")
        where string.startswith(path, inbound_root)
    ];
    That should do it!

  7. #137
    Join Date
    Jun 2010
    Posts
    85

    Default

    AWESOME! Works like a charm - too bad I can't increase your rep too many times in a row. I learned a few new things in the process too Thanks again!

  8. #138
    Join Date
    Jun 2010
    Posts
    85

    Default

    Hi Neilw - I am back again! Is there any way to display the URI.parts separated in different columns in a TSTable?
    Our 'paths' are just too long (and hideous due to custom sorting) to display as you do in the TSTable examples.

    Example: path = 'http://wiki.team-mediaportal.com/index.php?title=1_MEDIAPORTAL_1/17_Extensions/3_Plugins/My_Films'

    What I want to display in TSTable columns (|) : MediaPortal 1 | Extensions | Plugins | My Films
    So I can sort by any of those columns - only the Page title really needs a link, but I know how to do that

    Option 2 would be a way to display a 'pretty path' e.g. "MediaPortal 1/Extensions/Plugins/My Films" as that would sort pages correctly too, but I couldn't figure out how to do that either!

    I can get close with:
    Code:
     
    { key:"(web.link($.parent['uri'],$.parent.parent['title']))", title:"Section" },
    { key:"(web.link($.parent['uri'],$.parent['title']))", title:"Sub Section" },
    But that doesn't reflect the structure correctly.
    Breadcrumbs would work perfectly but I can't find a Dekiscript function for those - IIUC they are PHP functions used in skin.
    Last edited by dadeo; 09-19-2012 at 05:31 AM.

  9. #139
    Join Date
    Mar 2008
    Posts
    1,630

    Default

    I'm not sure if I understand all the details of the request, so let's see if we can sort this out (pardon the pun):

    Example: path = 'http://wiki.team-mediaportal.com/index.php?title=1_MEDIAPORTAL_1/17_Extensions/3_Plugins/My_Films'

    What I want to display in TSTable columns (|) : MediaPortal 1 | Extensions | Plugins | My Films
    So I can sort by any of those columns
    First things I note:
    1) That's a URI, not a path, and it's the URI you'll typically see right after you create the page. The actual URI is http://wiki.team-mediaportal.com/1_M...ugins/My_Films, and the actual path is 1_MEDIAPORTAL_1/17_Extensions/3_Plugins/My_Films.
    2) You've added numeric prefixes to the URL to the page titles to control sorting.
    3) If you want each part of the path to be in a column, does that mean you always know exactly how many parts there will be? If I go up or down the hierarchy, the number of parts will change. How did you want to handle this? What set of pages did you want in the TSTable?

    I created an account on your wiki (very nice, BTW) to experiment a bit. I'm not quite sure what you want the final table to look like, though. For the most part, splitting a path into its parts is a straightforward exercise, but I'll be able to help you better once I understand more precisely what you're aiming for. Would it be possible to create a page (in your personal space or mine, either way) and show me (a) the list of pages you'd want, and (b) a little sample of what the final table should look like, or at least the relevant parts?

  10. #140
    Join Date
    Jun 2010
    Posts
    85

    Default

    Thx Neil - yes you got all that correct. I already have a column for page title, so I only want the first two 'parts' or levels in the hierarchy in a 'Section' column. Ofc one option is to create separate tables for each section restricting data: wiki.getsearch to each section I want - but I'd end up with a lot of tables which kinda defeats part of the purpose of a sortable table

    The actual table which I want to change is our Wiki ToDo Lists (semi-public) and the test version I am playing with is ToDo TSTableTest private but I gave you access to that page - however our user access (via Joomla bridge) is limited to 'valid' users who have been members for 10 days with at least x forum posts so I am not sure if the permissions override that (never had a case before!) if not let me know and I can copy the test page to your user page.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts