Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Vis Timeline in C# class #4269

Open
forsharad opened this issue Mar 8, 2019 · 3 comments
Open

Vis Timeline in C# class #4269

forsharad opened this issue Mar 8, 2019 · 3 comments

Comments

@forsharad
Copy link

Hiya,

I have this C# class below which returns Communication on a particular date which I am able to print on an HTML table. Now I need to take that output in JSON format and pass-on to vis Timeline. I have no idea how I can do it. If I can use "For JSON" in SQL query it can return query output in JSON but still I want to put everything together in C# code from where I can create a dll with everything in it.

using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using Sage.CRM.Blocks;
using Sage.CRM.Controls;
using Sage.CRM.Data;
using Sage.CRM.HTML;
using Sage.CRM.Utils;
using Sage.CRM.WebObject;
using Sage.CRM.Graphics;
using Sage.CRM.UI;
using System.Data;

namespace QuickLook
{
class QuickLook : Web
{
public override void BuildContents()
{

        GetTabs();
        AddContent(HTML.Form());

//Communications
string strHtml = "

";
string varleadid= GetContextInfo("Lead", "Lead_leadid");
string querySQL = "select comm_createddate, Comm_Subject from vcommunication where comm_deleted is null and comm_leadid= " + varleadid;

        QuerySelect MyQuery = GetQuery();
        MyQuery.SQLCommand = querySQL;
        MyQuery.ExecuteReader();

        while (!MyQuery.Eof())
        {
            strHtml += "<tr><td class=viewbox>&nbsp;</td><td class=viewboxcaption>" + MyQuery.FieldValue("comm_createddate") + "</td><td>&nbsp;</td> <td class=viewbox>" + MyQuery.FieldValue("comm_subject") + "</td><td class=viewbox>&nbsp;</td><td class=viewbox>&nbsp;</td></tr>";
            MyQuery.Next();
        }
        strHtml += "</TABLE>";

        HorizontalPanel leadcomms = new HorizontalPanel();
        leadcomms.AddAttribute("width", "100%");
        leadcomms.AddAttribute("valign", "bottom");
        ContentBox cbLeadComm = new ContentBox();
        cbLeadComm.Title = varleadid;
        HTMLString htmlMessage = new HTMLString();
        htmlMessage.Html = strHtml;
        cbLeadComm.Inner = htmlMessage;
        leadcomms.Add(cbLeadComm);
        VerticalPanel vpMainPanel = new VerticalPanel();
        vpMainPanel.Add(leadcomms);
        AddContent(vpMainPanel.ToHtml());
    }
}

}

Thanks in Advance
Sharad

@Jogai
Copy link

Jogai commented Mar 11, 2019

I'd recommend to learn asp.net first and then about integrating with Sage CRM. I got the feeling that you're on the wrong way. Also this component is not really trivial to integrate. That said, here is a bit of code from a project where I have it integrated:

The action on the controller:

    [HttpGet]
    [AjaxOnly]
    public JsonResult Data(int id, int pos, DateTime startDate, DateTime endDate)
    {
        //Read data from db:
        var result = _db.Schemas.ReadMyData(siteId, pos, startDate, endDate).ToList();

        //Create groups out of the results
        List<object> mainGroups = new List<object>
        {
            new
            {
                id = no + 1,
                order = 1L,
                content = "MainGroup",
                //nestedGroups = set nested groups as needed
            }                
        };            

        //Return the whole thing as json
        return Json(new
        {
            mainGroups,
            result
        }, JsonRequestBehavior.AllowGet);
    }

Then if your results map to the groups and items of vis you can do:

                    // DOM element where the Timeline will be attached
                    let container = document.getElementById("visElement");
                    $(container).empty(); // Empty out the html. Renders the overview faster than updating existing data

                    // create a data set with groups
                    let groups = new DataSet();
                    // Create a DataSet (allows two way data-binding)
                    let items = new DataSet();
                    groups.add(data.mainGroups); 
                    items.add(data.result); 
                    // create a Timeline
                    var timeLine = new Timeline(container, items, groups, options);

@forsharad
Copy link
Author

Hi Jogai,

Thanks for this, even I was not sure for my approach that's the reason I raised it here. I can see you are using Ajax. Before thinking for this approach I wish to know, is it possible to call vis libraries in C# ?

The way I work in Sage CRM. I have created a .net dll (from the code I shared on top) which is capable of fetching data in JSON, now I was thinking if I can call vis libraries in .Net and display the vis Timeline from their, it will make my life simple.

Thanks in advance !
Sharad

@Jogai
Copy link

Jogai commented Mar 11, 2019

No, its a clientside library.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants