Hi I made some test with custom columns and I don't understand why in this test grouping is not working, not even auto group, Can somebody help me out?
This is the code.
// The OnInit function is called by Directory Opus to initialize the script add-in
var months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"]
function OnInit(initData) {
// Provide basic information about the script by initializing the properties of the ScriptInitData object
initData.name = "ByDate";
initData.default_enable = true;
//Set to true if you want to use dates for folders instead of the newest inside.
initData.config.UseFolderDate = false;
//Set maximum items to recurse inside a folder
initData.config.maxItemsPerFolder = 10;
// Create a new ScriptColumn object and initialize it to add the column to Opus
var cmd = initData.AddColumn();
cmd.name = "ByDate";
cmd.method = "ByDate";
cmd.label = "Creación | Modif.";
cmd.multicol = false;
cmd.autogroup = true; // we provide our own grouping information
cmd.autorefresh = true; // auto-refresh column when file changes
cmd.type = "datetime";
// cmd.grouporder = "Del Futuro!;Hoy;Esta semana;Este mes;Este año;El año pasado;Hace mucho tiempo";
}
function ByDate(scriptColData) {
item_time = scriptColData.item.create.Compare(scriptColData.item.modify) > 0 ? scriptColData.item.create : scriptColData.item.modify;
//if item is dir and UseFolderDate is false we pick the date from inside the folder
if (scriptColData.item.is_dir && !Script.config.UseFolderDate)
{
var i = 1;
FolderEnum = DOpus.FSUtil.ReadDir(scriptColData.item, false);
while (!FolderEnum.complete && i < Script.config.maxItemsPerFolder)
{
FolderItem = FolderEnum.next;
ntime = FolderItem.create.Compare(FolderItem.modify) > 0 ? FolderItem.create : FolderItem.modify;
if (item_time.Compare(ntime) < 0)
item_time = ntime;
i++;
}
}
scriptColData.value = item_time.Format();
// var today = DOpus.NewDate();
// if (today.Compare(item_time) == -1)
// {
// DOpus.Output("Del Futuro!");
// scriptColData.group = "Del Futuro!";
// scriptColData.sort = 1;
// }
// else if (today.Compare(item_time, "d"))
// {
// scriptColData.group = "Hoy";
// scriptColData.sort = 2;
// }
// // Si son de la misma semana
// // else if (today.year == item_time.year)
// // {
// // var group = "Este año";
// // var sort = 5;
// // //Si son del mismo mes
// // if (today.month == item_time.month)
// // {
// // sort = 4;
// // group = "Este mes";
// // //Si son de la misma semana
// // if (today.day - today.wday == item_time.day - item_time.wday)
// // {
// // sort = 3;
// // group = "Esta semana";
// // //Si son del mismo dia
// // }
// // }
// // DOpus.Output(group);
// // scriptColData.group = group;
// // scriptColData.sort = sort;
// // }
// //Si es del año pasado
// else if (today.year - 1 == item_time.year) {
// DOpus.Output("El año pasado");
// scriptColData.group = "El año pasado";
// scriptColData.sort = 6;
// }
// // Es de hace mucho tiempo
// else {
// DOpus.Output("Hace tiempo");
// scriptColData.group = "Hace tiempo";
// scriptColData.sort = 7;
// }
}
PS: The column that I want to create acts(group, sorting) exactly as date related columns already, but instead use the newest date between creation/modification. Can somebody also help me out with a better code. The one above is too clumsy in my opinion.