public void load_objects(int?folder_id = null, int?synch_folder_id = null, task_filter tf = null, int?search_id = null) { // folders structure this.synch_folders = load_folders(folder_id, synch_folder_id, search_id); // tasks this.tasks = load_tasks(folder_id: folder_id, synch_folder_id: synch_folder_id, tf: tf, search_id: search_id); // task -> folder, file foreach (task t in this.tasks) { if (t.folder_id.HasValue && !t.file_id.HasValue) { this.synch_folders.First(x => x.id == t.synch_folder_id).get_folder(t.folder_id.Value).task = t; } else { this.synch_folders.First(x => x.id == t.synch_folder_id).get_file(t.file_id.Value).task = t; } } }
protected List <task> load_tasks(int?task_id = null, int?folder_id = null, int?synch_folder_id = null, task_filter tf = null, int?search_id = null) { // filtro string filters = tf != null ? tf.def : ""; if (filters != "") { int i_filter = filters.IndexOf("{"); while (i_filter >= 0) { int i_end = filters.IndexOf("}", i_filter); if (i_end <= 0) { throw new Exception("il filtro '" + tf.def + "' non è definito correttamente!"); } string sub = filters.Substring(i_filter, (i_end - i_filter) + 1); // vedo se c'è un campo string field = "", name_field = ""; int f_from = sub.IndexOf("["); if (f_from >= 0) { int f_end = sub.IndexOf("]", f_from); if (f_end <= 0) { throw new Exception("il filtro '" + tf.def + "' non è definito correttamente!"); } field = sub.Substring(f_from, (f_end - f_from) + 1); name_field = field.Substring(1, field.Length - 2).Trim(); } string new_sub = sub.Substring(1, sub.Length - 2).Replace(field, "t3." + name_field); filters = filters.Replace(sub, new_sub); i_filter = filters.IndexOf("{"); } } string[,] pars = new string[, ] { { "task_id", task_id.HasValue ? task_id.Value.ToString() : "null" } , { "folder_id", folder_id.HasValue ? folder_id.Value.ToString() : "null" } , { "search", search_id.HasValue ? "true" : "false" }, { "search_id", search_id.HasValue ? search_id.Value.ToString() : "0" } , { "synch_folder_id", synch_folder_id.HasValue ? synch_folder_id.Value.ToString() : "null" } , { "filter_sf", !synch_folder_id.HasValue && folder_id.HasValue ? " ft.tp <> 'synch_folder' and " : "" } , { "filters", filters != "" ? " and " + filters : "" } }; return(db_conn.dt_table(core.parse_query("lib-notes.tasks", pars)).Rows.Cast <DataRow>() .Select(dr => new task(db_provider.int_val(dr["synch_folder_id"]), db_provider.long_val(dr["task_id"]) , db_provider.long_val_null(dr["file_id"]), db_provider.long_val_null(dr["folder_id"]) , db_provider.str_val(dr["title"]), db_provider.str_val(dr["user"]) , db_provider.dt_val(dr["dt_lwt"]), db_provider.dt_val(dr["dt_ref"]), db_provider.dt_val(dr["dt_ins"]), db_provider.dt_val(dr["dt_upd"]) , new task_stato(db_provider.str_val(dr["stato"]), db_provider.int_val(dr["stato_order"], 99) , db_provider.str_val(dr["stato_class"]), db_provider.str_val(dr["stato_title_plurale"]), db_provider.str_val(dr["stato_title_singolare"])) , new task_priorita(db_provider.str_val(dr["priorita"]), db_provider.int_val(dr["priorita_order"], 99) , db_provider.str_val(dr["priorita_class"]), db_provider.str_val(dr["priorita_title_plurale"]), db_provider.str_val(dr["priorita_title_singolare"])) , new task_stima(db_provider.str_val(dr["stima"]), db_provider.float_val(dr["stima_days"]) , db_provider.str_val(dr["stima_class"]), db_provider.str_val(dr["stima_title_plurale"]), db_provider.str_val(dr["stima_title_singolare"])) , new task_tipo(db_provider.str_val(dr["tipo"]), db_provider.int_val(dr["tipo_order"], 99) , db_provider.str_val(dr["tipo_class"]), db_provider.str_val(dr["tipo_title_plurale"]), db_provider.str_val(dr["tipo_title_singolare"])) , db_provider.int_val(dr["task_notes"]) == 1, db_provider.int_val(dr["task_files"]) == 1)).ToList()); }
protected string parse_tasks(notes n, List <task_stato> stati, task_filter tf = null, string title_folder = "", string path_folder = "" , List <task_filter> tfs = null, string search = "") { StringBuilder sb = new StringBuilder(); sb.Append(core.parse_html_block(search != "" ? (title_folder == "" ? "title-attivita-search" : "title-attivita-folder-search") : (title_folder == "" ? "title-attivita" : "title-attivita-folder") , new string[, ] { { "title-folder", title_folder }, { "path-folder", path_folder } , { "filter-title", search != "" ? "ricerca attività" : (tf != null ? tf.title : "") } , { "filter-des", (search != "" ? "ricerca attività che contengono '" + search + "'" : "") + (tf != null ? tf.notes + " ordinate per data decrescente" : "") } , { "conteggio", n.tasks != null && n.tasks.Count > 0 ? "per un totale di: " + n.tasks.Count.ToString() + " attività" : "non è stata trovata nessuna attività" } , { "html-filters", tfs != null ? string.Join("", tfs.Select(x => string.Format("<a class='dropdown-item {2}' href='javascript:change_filter({1})'>{0}</a>", x.title, x.id, x.class_css != "" ? "text-" + x.class_css : ""))) : "" } })); List <int> orders = n.tasks.Select(x => x.stato.order).Distinct().ToList(); orders.Sort(); foreach (int order in orders) { bool first = true; List <task> sub_tasks = n.tasks.Where(x => x.stato.order == order).OrderByDescending(xx => xx.dt_ref).ToList(); foreach (task t in sub_tasks) { // title if (first) { string sub_title = sub_tasks.Count == 1 ? t.stato.title_singolare : t.stato.title_plurale; sb.Append(core.parse_html_block("open-title-sub-attivita", new string[, ] { { "count", sub_tasks.Count.ToString() }, { "cls", t.stato.cls } , { "title", sub_title != "" ? sub_title : (sub_tasks.Count == 1 ? "GENERICA" : "GENERICHE") } })); first = false; } // task string folder_path = ""; if (t.file_id.HasValue) { folder f = t.folder_id.HasValue ? n.synch_folders.FirstOrDefault(x => x.id == t.synch_folder_id).get_folder(t.folder_id.Value) : null; folder_path = f != null ? f.path : ""; } else { synch_folder sf = n.synch_folders.FirstOrDefault(x => x.id == t.synch_folder_id); folder f = sf.get_folder(t.folder_id.Value) , fp = f.parent_id.HasValue ? sf.get_folder(f.parent_id.Value) : null; folder_path = fp != null ? fp.path : ""; } sb.Append(parse_task(t, n.find_synch_folder(t.synch_folder_id).title + folder_path, stati)); } if (!first) { sb.Append(core.parse_html_block("close-title-sub-attivita")); } } return(sb.ToString()); }
protected override void OnInit(EventArgs e) { base.OnInit(e); // inizializzazione _cmd = master.check_cmd(qry_val("cmd")); // elab requests & cmds if (this.IsPostBack) { return; } try { notes ob = new notes(); // upload file if (json_request.there_file(this)) { json_result res = new json_result(json_result.type_result.ok); try { if (Request.Files.Count > 0) { HttpFileCollection files = Request.Files; foreach (string key in files) { HttpPostedFile file = files[key]; string tp_file = key.Split(new char[] { '_' })[0]; if (tp_file == "task-file") { int task_id = int.Parse(key.Split(new char[] { '_' })[2]); byte[] content; using (var streamReader = new MemoryStream()) { file.InputStream.CopyTo(streamReader); content = streamReader.ToArray(); } add_att(ob, task_id, Path.GetFileName(file.FileName), content); } else { throw new Exception("tipo file upload '" + tp_file + "' non supportato!"); } } } else { throw new Exception("nessun file da caricare!"); } } catch (Exception ex) { log.log_err(ex); res = new json_result(json_result.type_result.error, ex.Message); } write_response(res); return; } // js request if (json_request.there_request(this)) { json_result res = new json_result(json_result.type_result.ok); try { json_request jr = new json_request(this); // base if (base_elab_action(jr, res)) { // fatta } // add_att else if (jr.action == "add_att") { add_att(ob, jr.val_int("task_id"), jr.val_str("name")); } // task_state else if (jr.action == "task_state") { List <free_label> fl = ob.load_free_labels(); string folder_path; ob.update_task(jr.val_int("id"), out folder_path, fl, stato: jr.val_str("stato")); List <task_stato> stati = db_conn.dt_table(core.parse_query("menu-states")).Rows.Cast <DataRow>() .Select(r => new task_stato(db_provider.str_val(r["stato"]), 0, "", "" , db_provider.str_val(r["title_singolare"]))).ToList(); res.html_element = parse_task(ob.load_task(jr.val_int("id")), folder_path, stati); } // set_filter_id else if (jr.action == "set_filter_id") { set_cache_var("active-task-filter", jr.val_str("filter_id")); } // remove_task else if (jr.action == "remove_task") { ob.remove_task(jr.val_int("id")); } // update_task else if (jr.action == "update_task") { List <free_label> fl = ob.load_free_labels(); if (!nome_valido(jr.val_str("title"))) { throw new Exception("nome '" + jr.val_str("title") + "' non valido!"); } string folder_path; ob.update_task(jr.val_int("id"), out folder_path, fl, title: jr.val_str("title"), assegna: jr.val_str("assegna") , priorita: jr.val_str("priorita"), stima: jr.val_str("stima"), tipo: jr.val_str("tipo")); List <task_stato> stati = db_conn.dt_table(core.parse_query("menu-states")).Rows.Cast <DataRow>() .Select(r => new task_stato(db_provider.str_val(r["stato"]), 0, "", "" , db_provider.str_val(r["title_singolare"]))).ToList(); res.html_element = parse_task(ob.load_task(jr.val_int("id")), folder_path, stati); } // ren_task else if (jr.action == "ren_task") { if (!nome_valido(jr.val_str("title"))) { throw new Exception("nome '" + jr.val_str("title") + "' non valido!"); } ob.ren_task(jr.val_int("id"), jr.val_str("title")); } // add_task else if (jr.action == "add_task") { if (!nome_valido(jr.val_str("title"))) { throw new Exception("nome '" + jr.val_str("title") + "' non valido!"); } ob.add_task(jr.val_int("synch_folder_id"), jr.val_int("folder_id"), jr.val_int_null("search_id"), jr.val_str("stato") , jr.val_str("title"), jr.val_str("assegna"), jr.val_str("priorita"), jr.val_str("tipo"), jr.val_str("stima")); } // remove_att else if (jr.action == "remove_att") { ob.remove_att(jr.val_int("id")); } // ren_att else if (jr.action == "ren_att") { ob.ren_file(jr.val_int("file_id"), jr.val_str("name")); } // add_folder else if (jr.action == "add_folder") { if (!nome_valido(jr.val_str("title"))) { throw new Exception("nome '" + jr.val_str("title") + "' non valido!"); } ob.add_folder(jr.val_int("synch_folder_id"), jr.val_int("folder_id"), jr.val_str("title")); } // ren_folder else if (jr.action == "ren_folder") { if (!nome_valido(jr.val_str("title"))) { throw new Exception("nome '" + jr.val_str("title") + "' non valido!"); } ob.ren_folder(jr.val_int("synch_folder_id"), jr.val_int("folder_id"), jr.val_str("title")); } // del_folder else if (jr.action == "del_folder") { ob.del_folder(jr.val_int("synch_folder_id"), jr.val_int("folder_id")); res.contents = master.url_cmd("tasks"); } // cut_element else if (jr.action == "cut_element") { int f_id = jr.val_int("element_id"), sf_id = jr.val_int("synch_folder_id"); string tp = jr.val_str("tp_element"); bool?added = null; if (tp == "folder" || tp == "synch-folder") { if (sf_id > 0 && tp == "synch-folder") { foreach (int id in ob.ids_childs_folders(sf_id)) { added = set_element_cut(id, element_cut.element_cut_type.folder, jr.val_bool("copy")); res.list.Add(id.ToString()); } } else { added = set_element_cut(f_id, element_cut.element_cut_type.folder, jr.val_bool("copy")); res.list.Add(f_id.ToString()); } } else if (tp == "task") { added = set_element_cut(f_id, element_cut.element_cut_type.task, jr.val_bool("copy")); } else if (tp == "att") { added = set_element_cut(f_id, element_cut.element_cut_type.attachment, jr.val_bool("copy")); } res.set_var("added", added.HasValue ? (added.Value ? "true" : "false") : "none"); } // paste_elements else if (jr.action == "paste_elements") { string tp_paste = jr.val_str("tp"); int f_id = jr.val_int("folder_id"), sf_id = jr.val_int("synch_folder_id"); bool paste = false; if (elements_cut.Count > 0) { string err = ""; List <element_cut> ecs = new List <element_cut>(); if (tp_paste == "task") { DataRow dr = ob.get_task_info(f_id); if (db_provider.int_val(dr["file_id"]) > 0) { throw new Exception("questo task non può contenere un allegato!"); } string path_task = Path.Combine(db_provider.str_val(dr["synch_local_path"]) , db_provider.str_val(dr["folder_path"]).Length > 0 ? db_provider.str_val(dr["folder_path"]).Substring(1) : ""); foreach (element_cut ec in elements_cut) { try { if (ec.tp == element_cut.element_cut_type.attachment) { paste = true; if (!ec.copy) { ob.move_file(ec.id, db_provider.int_val(dr["folder_id"]), db_provider.int_val(dr["synch_folder_id"]), path_task); } else { ob.copy_file(ec.id, db_provider.int_val(dr["folder_id"]), db_provider.int_val(dr["synch_folder_id"]), path_task); } } } catch (Exception ex) { ecs.Add(ec); if (err == "") { err = ex.Message; } } } } else { if (sf_id <= 0) { sf_id = ob.get_synch_folder_id(f_id); } foreach (element_cut ec in elements_cut) { try { if (ec.tp == element_cut.element_cut_type.folder) { ob.move_folder(ec.id, sf_id, f_id > 0 ? f_id : (int?)null); paste = true; } else if (ec.tp == element_cut.element_cut_type.task) { ob.move_task(ec.id, sf_id, f_id > 0 ? f_id : (int?)null); paste = true; } } catch (Exception ex) { ecs.Add(ec); if (err == "") { err = ex.Message; } } } } res.message = err; elements_cut.Clear(); foreach (element_cut ec2 in ecs) { elements_cut.Add(ec2); } } if (!paste) { throw new Exception("non è stato incollato nessun elemento!"); } } // get_notes else if (jr.action == "get_details") { res.contents = ob.get_task_notes(jr.val_int("task_id")); string html_allegati = ""; foreach (DataRow dr in ob.get_task_allegati(jr.val_int("task_id"), jr.val_int_null("search_id")).Rows) { bool cut = there_element_cut(db_provider.int_val(dr["file_id"]), element_cut.element_cut_type.attachment) , found = db_provider.int_val(dr["found_file"]) > 0, file_task = db_provider.int_val(dr["file_task"]) > 0; string style = cut ? "badge-warning" : (found ? "badge-danger" : (file_task ? "badge-primary" : "badge-light")); html_allegati += master.client_key == "" ? core.parse_html_block("task-allegato", new string[, ] { { "file-id", db_provider.str_val(dr["file_id"]) } , { "http-path", db_provider.str_val(dr["http_path"]) }, { "file-name", db_provider.str_val(dr["file_name"]) }, { "style", style }, { "tp_att", style } }) : core.parse_html_block("task-allegato-client", new string[, ] { { "file-id", db_provider.str_val(dr["file_id"]) }, { "file-name", db_provider.str_val(dr["file_name"]) }, { "style", style }, { "tp_att", style } , { "user-id", ob.user_id.ToString() }, { "user-name", ob.user_name } }); } res.html_element = html_allegati != "" ? core.parse_html_block("task-allegati", new string[, ] { { "html-allegati", html_allegati } }) : ""; } // save_task_notes else if (jr.action == "save_task_notes") { synch s = ob.get_synch(jr.val_int("user_id"), jr.val_str("user_name")); s.save_task_notes(jr.val_int("task_id"), jr.val_str("text")); } else if (jr.action == "synch_folders") { synch s = ob.get_synch(jr.val_int("user_id"), jr.val_str("user_name")); s.synch_event += s_synch_event; synch_results rf = s.reload_folders(force: true); res.data = rf; res.contents = _synch_events; } } catch (Exception ex) { log.log_err(ex); res = new json_result(json_result.type_result.error, ex.Message); } write_response(res); return; } // synch if (_cmd != null && _cmd.action == "synch") { content.InnerHtml = "<p>sincronizzazione cartelle...</p>"; ClientScript.RegisterStartupScript(GetType(), "__action" , "var __action_page = '" + _cmd.action + "';\r\n" + "var __user_id = " + this.user.id + ";\r\n" + "var __user_name = '" + this.user.name + "';\r\n", true); } // tasks else if (_cmd != null && ((_cmd.action == "view" && _cmd.obj == "tasks") || (_cmd.action == "search" && _cmd.obj == "task"))) { int?fi = qry_val("idt") != "" ? qry_int("idt") : (qry_val("id") != "" ? qry_int("id") : (int?)null) , sfi = qry_val("sft") != "" ? qry_int("sft") : (qry_val("sf") != "" ? qry_int("sf") : (int?)null); string search = _cmd.action == "search" ? _cmd.sub_obj() : ""; // ricerca testo int search_cc = 0; int?search_id = search != "" ? ob.search_task(search, this.Session.SessionID, out search_cc) : (int?)null; search_id_active.Value = search_id.HasValue ? search_id.Value.ToString() : ""; // filtro attivo List <task_filter> tfs = db_conn.dt_table(core.parse_query("filters-tasks")).Rows .Cast <DataRow>().Select(r => new task_filter(db_provider.int_val(r["task_filter_id"]) , db_provider.str_val(r["filter_title"]), db_provider.str_val(r["filter_notes"]) , db_provider.str_val(r["filter_def"]), db_provider.str_val(r["filter_class"]))).ToList(); task_filter tf = tfs.FirstOrDefault(x => x.id == int.Parse(get_cache_var("active-task-filter", "1"))); if (tf == null || search_id.HasValue) { tf = new task_filter(0, "elenco completo delle attività", "", "", ""); } ob.load_objects(fi, sfi, tf, search_id); menu.InnerHtml = parse_menu(ob.synch_folders, sfi.HasValue || fi.HasValue, qry_val("cmd"), search_id); folder_id.Value = qry_val("id"); folder f = fi.HasValue ? ob.find_folder(fi.Value) : null; synch_folder sf = sfi.HasValue ? ob.find_synch_folder(sfi.Value) : null; string title = f != null ? f.folder_name : (sf != null ? sf.title : ""); List <task_stato> stati = db_conn.dt_table(core.parse_query("menu-states")).Rows.Cast <DataRow>() .Select(r => new task_stato(db_provider.str_val(r["stato"]), 0, "", "", db_provider.str_val(r["title_singolare"]))).ToList(); content.InnerHtml = "<div style='display:none'>virtuale</div>" + parse_tasks(ob, stati, tf, title, f != null ? ob.find_synch_folder(f.synch_folder_id).title + f.path : "", tfs, search: search_id.HasValue ? search : ""); ClientScript.RegisterStartupScript(GetType(), "__task_states" , "var __action_page = '';\r\n" + "var __task_priorita = " + JsonConvert.SerializeObject(db_conn.dt_table(core.parse_query("task-priorita"))) + ";\r\n" + "var __task_stime = " + JsonConvert.SerializeObject(db_conn.dt_table(core.parse_query("task-stime"))) + ";\r\n" + "var __task_tipi = " + JsonConvert.SerializeObject(db_conn.dt_table(core.parse_query("task-tipi"))) + ";\r\n" + "var __task_assegna = " + JsonConvert.SerializeObject(db_conn.dt_table(core.parse_query("task-assegna"))) + ";\r\n" + "var __user_id = " + this.user.id + ";\r\n" + "var __user_name = '" + this.user.name + "';\r\n", true); } else { throw new Exception("COMANDO NON RICONOSCIUTO!"); } } catch (Exception ex) { log.log_err(ex); if (!json_request.there_request(this)) { master.err_txt(ex.Message); } } }