#112892
sparki smith
Participant

Hello Markov,

I have reviewed the provided demo, unfortunately it does not showcase how the Kanban component should be used. Instead it demonstrates how to create a service, fetching data from DB. This is not what I asked for.

On the other hand, your note about the UpdateTask() method pushed me in the correct direction. I tested it out and the GanttChart works as expected. I believe I can use the component for my last evaluation test.

The Kanban however does not work in the same way. It simply does not update using the same method and shape of objects.
I looked through the available repositories and I managed to find the example, demonstrating how the UpdateTask() can be used in the Kanban. Here is link to the exact page I investigated
https://github.com/HTMLElements/smart-blazor/blob/main/Smart.Blazor.Demos/Pages/KanbanDemos/KanbanMethodsPage.razor

I managed to recreate the issue I am facing with the Kanban in that page. At the end of this post I will paste the entire code of the mentioned page, so that you can take it and easily recreate the scenario on your end.

Long-story-short:
The DataSource is a custom object with GUID as Id. There is DataSourceMap to change the expected property names and custom logic for generating the required Dictionary<string,string> object which represent the changes which should be visualized by the Kanban.

Please inspect the code and let me know what is missing from it. Does the MyTask class fit the minimum requirements of the Kanban? What is lacking and why the Kanban can visualize this class but not update it at runtime?

 

 

Thank you for your cooperation!

<div>

@page "/kanban-methods"

@using System.Reflection
@using System.Text.Json.Serialization

        <Kanban @ref="kanban" DataSource="dataRecords" DataSourceMap="map" Columns="@columns" />

        <div class="options">
            <Button OnClick="UpdateTaskOnClick">Update task</Button>
        </div>

@code {

    public class MyTask
    {
        [JsonPropertyName("label")]
        public string Label { get; set; }
        [JsonPropertyName("status")]
        public string Status { get; set; }

        [JsonPropertyName("id")] public Guid Id { get; set; } = Guid.NewGuid();
    }

    Kanban kanban;

    Dictionary<string, string> map =
        new()
        {
            {"text", "label"}
        };


    List<KanbanColumn> columns = new List<KanbanColumn>()
    {
        new KanbanColumn()
        {
            DataField = "ToDo",
            Label = "To do"
        },
        new KanbanColumn()
        {
            DataField = "InProgress",
            Label = "In progress"
        },
        new KanbanColumn()
        {
            DataField = "Testing",
            Label = "Testing"
        },
        new KanbanColumn()
        {
            DataField = "Done",
            Label = "Done"
        }
    };
    
    private List<MyTask> dataRecords;
    private readonly Random _random = new();
    
    protected override void OnInitialized()
    {
        base.OnInitialized();
        dataRecords =
            new()
            {
                new MyTask()
                {
                    Label = $"Label: {_random.Next()}",
                    Status = "ToDo"
                },
                new MyTask()
                {
                    Label = $"Label: {_random.Next()}",
                    Status = "InProgress"
                },
                new MyTask()
                {
                    Label = $"Label: {_random.Next()}",
                    Status = "Testing"
                },
                new MyTask()
                {
                    Label = $"Label: {_random.Next()}",
                    Status = "Done"
                },
            };
    }

    private void UpdateTaskOnClick()
    {
        var toUpdate = dataRecords[0];
        toUpdate.Label = $"@@@@@@@@@@@@@@@@@@@@@@ {DateTime.Now}";
        
        var updateDict = ToDictionary(toUpdate);
        kanban.UpdateTask(toUpdate.Id, updateDict);
    }
    
    private static Dictionary<string, string> ToDictionary(object obj)
    {
        var dict = new Dictionary<string, string>();
        if (obj == null) return dict;

        
        PropertyInfo[] properties = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

        foreach (var prop in properties)
        {
            if (prop.Name == "Id") continue;
            
            
            string key = prop.Name;
            if (!string.IsNullOrEmpty(key) && char.IsUpper(key[0]))
            {
                key = char.ToLower(key[0]) + key.Substring(1);
            }
            
            object value = prop.GetValue(obj);
            string valueString = value?.ToString() ?? string.Empty;

            dict[key] = valueString;
        }

        return dict;
    }
}

</div>

  • This reply was modified 6 months, 3 weeks ago by sparki smith.