# # # get_simple_profiles_dat.cfv # # # # # # # get_simple_profiles_dat_by_index() # # # #subroutine(get_simple_profiles_dat_by_index( # node permitted_profiles, # int index_from, # index starts at 0 # int index_to), ( # # # This returns a JSON array with profile name, profile label # # and the default_date_filter objects for the given index. # # # permitted_profiles may be the original profiles node # # or a custom node which lists permitted profiles only. # # # # Sort the profiles node # sort(permitted_profiles, "field:label,alphabetical,ascending"); # # int num_profiles = num_subnodes(permitted_profiles); # # # Verify index_to # if (index_to >= num_profiles) then ( # index_to = num_profiles - 1; # ); # # string profiles_dat = "["; # string profile_item_dat; # # if (index_from <= index_to) then ( # # node profile; # bool is_valid_profile; # string version; # string name; # string label; # string default_date_filter; # # for (int i = index_from; i <= index_to; i++) ( # # profile = subnode_by_number(permitted_profiles, i); # # # Make sure that the profile isn't from an older version # # is_valid_profile = get_is_valid_profile(profile); # # name = node_name(profile); # label = @profile{"label"}; # default_date_filter = ""; # # if (?(profile . ".statistics.miscellaneous.date_filter.df")) then ( # default_date_filter = @(profile . ".statistics.miscellaneous.date_filter.df"); # ) # else if (?(profile . ".default_date_filter")) then ( # # This is a profile node with limited profile data which we got from get_permitted_profiles() # default_date_filter = @(profile . ".default_date_filter"); # ); # # profile_item_dat = "{"; # profile_item_dat .= add_json("name", name, "string"); # profile_item_dat .= add_json("label", label, "string"); # profile_item_dat .= add_json("df", default_date_filter, "string"); # profile_item_dat = close_json(profile_item_dat); # # profiles_dat .= profile_item_dat . ","; # ); # # profiles_dat = replace_last(profiles_dat, ",", "]"); # ) # else ( # # profiles_dat .= "]"; # ); # # # Return # profiles_dat; #));