Skip to content

Commit

Permalink
Fixing List component example code (#1476)
Browse files Browse the repository at this point in the history
Co-authored-by: Ole Martin Handeland <[email protected]>
  • Loading branch information
olemartinorg and Ole Martin Handeland authored Mar 19, 2024
1 parent b15845d commit fdf6ac9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
21 changes: 17 additions & 4 deletions content/app/development/ux/components/listComponent/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ public class ListCases : IDataListProvider
{
public string Id { get; set; } = "people";

public async Task<DataList> GetDataListAsync(string language, Dictionary<string, string> keyValuePairs)
public Task<DataList> GetDataListAsync(string language, Dictionary<string, string> keyValuePairs)
{
int start = 0;
int count = 10;
string search = "";

if (keyValuePairs.ContainsKey("search") )
{
search = keyValuePairs["search"];
}

if (keyValuePairs.ContainsKey("size") && keyValuePairs.ContainsKey("page"))
{
Expand All @@ -82,6 +88,12 @@ public class ListCases : IDataListProvider
items.Add(new ListItem { Name = "Karl", Age = 49, Profession = "Skuespiller" });
items.Add(new ListItem { Name = "Mette", Age = 33, Profession = "Artist" });


if (!String.IsNullOrEmpty(search))
{
items = items.Where(o => (o.Name == search)).ToList();
}

if (keyValuePairs.ContainsKey("sortDirection"))
{
string sortDirection = keyValuePairs["sortDirection"];
Expand All @@ -95,13 +107,14 @@ public class ListCases : IDataListProvider
items.Reverse();
}
}

DataListMetadata appListsMetaData = new DataListMetadata() { TotaltItemsCount = items.Count };

List<object> objectList = new List<object>();
items.ForEach(o => objectList.Add(o));

return new DataList { ListItems = objectList.GetRange(start, count), _metaData = appListsMetaData };
int boundedCount = start + count > items.Count ? items.Count - start : count;
return Task.FromResult(new DataList { ListItems = objectList.GetRange(start, boundedCount), _metaData = appListsMetaData });
}
}
```
Expand Down
21 changes: 17 additions & 4 deletions content/app/development/ux/components/listComponent/_index.nb.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ public class ListCases : IDataListProvider
{
public string Id { get; set; } = "people";

public async Task<DataList> GetDataListAsync(string language, Dictionary<string, string> keyValuePairs)
public Task<DataList> GetDataListAsync(string language, Dictionary<string, string> keyValuePairs)
{
int start = 0;
int count = 10;
string search = "";

if (keyValuePairs.ContainsKey("search") )
{
search = keyValuePairs["search"];
}

if (keyValuePairs.ContainsKey("size") && keyValuePairs.ContainsKey("page"))
{
Expand All @@ -82,6 +88,12 @@ public class ListCases : IDataListProvider
items.Add(new ListItem { Name = "Karl", Age = 49, Profession = "Skuespiller" });
items.Add(new ListItem { Name = "Mette", Age = 33, Profession = "Artist" });


if (!String.IsNullOrEmpty(search))
{
items = items.Where(o => (o.Name == search)).ToList();
}

if (keyValuePairs.ContainsKey("sortDirection"))
{
string sortDirection = keyValuePairs["sortDirection"];
Expand All @@ -95,13 +107,14 @@ public class ListCases : IDataListProvider
items.Reverse();
}
}

DataListMetadata appListsMetaData = new DataListMetadata() { TotaltItemsCount = items.Count };

List<object> objectList = new List<object>();
items.ForEach(o => objectList.Add(o));

return new DataList { ListItems = objectList.GetRange(start, count), _metaData = appListsMetaData };
int boundedCount = start + count > items.Count ? items.Count - start : count;
return Task.FromResult(new DataList { ListItems = objectList.GetRange(start, boundedCount), _metaData = appListsMetaData });
}
}
```
Expand Down

0 comments on commit fdf6ac9

Please sign in to comment.