diff --git a/server/DataList/GZCaseDataList.cs b/server/DataList/GZCaseDataList.cs index 5fb18f3..2381c7c 100644 --- a/server/DataList/GZCaseDataList.cs +++ b/server/DataList/GZCaseDataList.cs @@ -5,7 +5,7 @@ using Sockeye.Models; namespace Sockeye.DataList { - internal class GZCaseDataList : DataListProcessingBase + internal class GZCaseDataList : DataListProcessingBase, IDataListInternalCriteria { public GZCaseDataList(long translationId) { @@ -17,7 +17,7 @@ namespace Sockeye.DataList DefaultColumns = new List() { "GZCaseId", "Tags", "GZCaseName", "GZCaseClosed" }; DefaultSortBy = new Dictionary() { { "GZCaseId", "-" } }; FieldDefinitions = new List(); - + FieldDefinitions.Add(new DataListFieldDefinition { @@ -62,7 +62,55 @@ namespace Sockeye.DataList SqlValueColumnName = "agzcase.tags" }); - } + //META column + FieldDefinitions.Add(new DataListFieldDefinition + { + FieldKey = "metacustomer", + UiFieldDataType = (int)UiFieldDataType.InternalId, + SqlIdColumnName = "agzcase.customerid", + SqlValueColumnName = "agzcase, IDataListInternalCriteria.customerid", + IsMeta = true + }); + } + public List DataListInternalCriteria(long currentUserId, AuthorizationRoles userRoles, string clientCriteria) + { + List ret = new List(); + + //ClientCriteria format for this list is "OBJECTID,AYATYPE" + var crit = (clientCriteria ?? "").Split(',').Select(z => z.Trim()).ToArray(); + if (crit.Length > 1) + { + //will be filtered from different types, show all records from Customer and nothing else at this time + int nType = 0; + if (!int.TryParse(crit[1], out nType)) return ret; + SockType forType = (SockType)nType; + if (forType != SockType.Customer) return ret;//only supports customer for now see workorderdatalist for alts + + long lId = 0; + if (!long.TryParse(crit[0], out lId)) return ret; + if (lId == 0) return ret; + + //Have valid type, have an id, so filter away + switch (forType) + { + case SockType.Customer: + { + DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metacustomer" }; + FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality }); + ret.Add(FilterOption); + } + break; + // case AyaType.Project: + // { + // DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metaproject" }; + // FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality }); + // ret.Add(FilterOption); + // } + // break; + } + } + return ret; + } }//eoc }//eons \ No newline at end of file diff --git a/server/DataList/LicenseDataList.cs b/server/DataList/LicenseDataList.cs index a84c358..7d98017 100644 --- a/server/DataList/LicenseDataList.cs +++ b/server/DataList/LicenseDataList.cs @@ -5,7 +5,7 @@ using Sockeye.Models; namespace Sockeye.DataList { - internal class LicenseDataList : DataListProcessingBase + internal class LicenseDataList : DataListProcessingBase, IDataListInternalCriteria { public LicenseDataList(long translationId) { @@ -125,6 +125,56 @@ namespace Sockeye.DataList UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "alicense.dbid" }); + //META column + FieldDefinitions.Add(new DataListFieldDefinition + { + FieldKey = "metacustomer", + UiFieldDataType = (int)UiFieldDataType.InternalId, + SqlIdColumnName = "alicense.customerid", + SqlValueColumnName = "alicense.customerid", + IsMeta = true + }); + + } + + public List DataListInternalCriteria(long currentUserId, AuthorizationRoles userRoles, string clientCriteria) + { + List ret = new List(); + + //ClientCriteria format for this list is "OBJECTID,AYATYPE" + var crit = (clientCriteria ?? "").Split(',').Select(z => z.Trim()).ToArray(); + if (crit.Length > 1) + { + //will be filtered from different types, show all records from Customer and nothing else at this time + int nType = 0; + if (!int.TryParse(crit[1], out nType)) return ret; + SockType forType = (SockType)nType; + if (forType != SockType.Customer) return ret;//only supports customer for now see workorderdatalist for alts + + long lId = 0; + if (!long.TryParse(crit[0], out lId)) return ret; + if (lId == 0) return ret; + + //Have valid type, have an id, so filter away + switch (forType) + { + case SockType.Customer: + { + DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metacustomer" }; + FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality }); + ret.Add(FilterOption); + } + break; + // case AyaType.Project: + // { + // DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metaproject" }; + // FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality }); + // ret.Add(FilterOption); + // } + // break; + } + } + return ret; } }//eoc diff --git a/server/DataList/PurchaseDataList.cs b/server/DataList/PurchaseDataList.cs index d73ba59..824f20e 100644 --- a/server/DataList/PurchaseDataList.cs +++ b/server/DataList/PurchaseDataList.cs @@ -150,14 +150,40 @@ namespace Sockeye.DataList public List DataListInternalCriteria(long currentUserId, AuthorizationRoles userRoles, string clientCriteria) { List ret = new List(); - //ClientCriteria MUST be CustomerId - if (string.IsNullOrWhiteSpace(clientCriteria)) - throw new System.ArgumentNullException("CustomerNoteDataList - ClientCriteria is empty, should be Customer ID"); - DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metacustomer" }; - FilterOption.Items.Add(new DataListColumnFilter() { value = clientCriteria, op = DataListFilterComparisonOperator.Equality }); + //ClientCriteria format for this list is "OBJECTID,AYATYPE" + var crit = (clientCriteria ?? "").Split(',').Select(z => z.Trim()).ToArray(); + if (crit.Length > 1) + { + //will be filtered from different types, show all records from Customer and nothing else at this time + int nType = 0; + if (!int.TryParse(crit[1], out nType)) return ret; + SockType forType = (SockType)nType; + if (forType != SockType.Customer) return ret;//only supports customer for now see workorderdatalist for alts - ret.Add(FilterOption); + long lId = 0; + if (!long.TryParse(crit[0], out lId)) return ret; + if (lId == 0) return ret; + + //Have valid type, have an id, so filter away + switch (forType) + { + case SockType.Customer: + { + DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metacustomer" }; + FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality }); + ret.Add(FilterOption); + } + break; + // case AyaType.Project: + // { + // DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metaproject" }; + // FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality }); + // ret.Add(FilterOption); + // } + // break; + } + } return ret; } diff --git a/server/DataList/SubscriptionServerDataList.cs b/server/DataList/SubscriptionServerDataList.cs index d4c83af..78283bf 100644 --- a/server/DataList/SubscriptionServerDataList.cs +++ b/server/DataList/SubscriptionServerDataList.cs @@ -5,7 +5,7 @@ using Sockeye.Models; namespace Sockeye.DataList { - internal class SubscriptionServerDataList : DataListProcessingBase + internal class SubscriptionServerDataList : DataListProcessingBase, IDataListInternalCriteria { public SubscriptionServerDataList(long translationId) { @@ -17,26 +17,6 @@ namespace Sockeye.DataList DefaultColumns = new List() { "SubServerSubExpire", "SubServerName", "Customer", "SubServerTrial", "SubServerDatacenter", "Active" }; DefaultSortBy = new Dictionary() { { "SubServerSubExpire", "+" } }; FieldDefinitions = new List(); - /* - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubscriptionServer', 'Subscription server' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubscriptionServerList', 'Subscription servers' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerName', 'Name' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerNotes', 'Notes' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerDatacenter', 'Data center' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerTimeZone', 'Time zone' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerLastUpdated', 'Last updated' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerSubExpire', 'Subscription expires' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerTrialContact', 'Trial contact' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerTrialEmail', 'TrialEmail' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerTrial', 'Trial' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerTrialCompany', 'Trial company' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerOperatingSystem', 'OS' FROM atranslation t where t.baselanguage = 'en'"); - await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SubServerCustomerDomain', 'Customer subdomain' FROM atranslation t where t.baselanguage = 'en'"); -"CREATE TABLE asubscriptionserver (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, active BOOL NOT NULL DEFAULT true, created TIMESTAMPTZ NOT NULL, " -+ "name TEXT NOT NULL, notes TEXT, datacenter TEXT NOT NULL, timezone TEXT NOT NULL, dbid TEXT, lastupdated TIMESTAMPTZ, subscriptionexpire TIMESTAMPTZ NOT NULL, " -+ "trial BOOL NOT NULL DEFAULT true, trialcontact TEXT, trialemail TEXT, trialcompany TEXT, operatingsystem TEXT, customersubdomain TEXT, " -+ "wiki TEXT, tags VARCHAR(255) ARRAY, customerid BIGINT REFERENCES acustomer(id) )" - */ FieldDefinitions.Add(new DataListFieldDefinition { @@ -181,6 +161,56 @@ namespace Sockeye.DataList SqlValueColumnName = "asubscriptionserver.tags" }); + //META column + FieldDefinitions.Add(new DataListFieldDefinition + { + FieldKey = "metacustomer", + UiFieldDataType = (int)UiFieldDataType.InternalId, + SqlIdColumnName = "asubscriptionserver.customerid", + SqlValueColumnName = "asubscriptionserver.customerid", + IsMeta = true + }); + + } + + public List DataListInternalCriteria(long currentUserId, AuthorizationRoles userRoles, string clientCriteria) + { + List ret = new List(); + + //ClientCriteria format for this list is "OBJECTID,AYATYPE" + var crit = (clientCriteria ?? "").Split(',').Select(z => z.Trim()).ToArray(); + if (crit.Length > 1) + { + //will be filtered from different types, show all records from Customer and nothing else at this time + int nType = 0; + if (!int.TryParse(crit[1], out nType)) return ret; + SockType forType = (SockType)nType; + if (forType != SockType.Customer) return ret;//only supports customer for now see workorderdatalist for alts + + long lId = 0; + if (!long.TryParse(crit[0], out lId)) return ret; + if (lId == 0) return ret; + + //Have valid type, have an id, so filter away + switch (forType) + { + case SockType.Customer: + { + DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metacustomer" }; + FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality }); + ret.Add(FilterOption); + } + break; + // case AyaType.Project: + // { + // DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metaproject" }; + // FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality }); + // ret.Add(FilterOption); + // } + // break; + } + } + return ret; } }//eoc diff --git a/server/biz/GZCaseBiz.cs b/server/biz/GZCaseBiz.cs index d610555..88d12c5 100644 --- a/server/biz/GZCaseBiz.cs +++ b/server/biz/GZCaseBiz.cs @@ -255,7 +255,7 @@ namespace Sockeye.Biz foreach (GZCase w in orderedList) { if (!ReportRenderManager.KeepGoing(jobId)) return null; - + await PopulateVizFields(w); var jo = JObject.FromObject(w); if (!JsonUtil.JTokenIsNullOrEmpty(jo["CustomFields"])) jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]); @@ -269,7 +269,15 @@ namespace Sockeye.Biz private VizCache vc = new VizCache(); - + //populate viz fields from provided object + private async Task PopulateVizFields(GZCase o) + { + if (!vc.Has("customer", o.CustomerId)) + { + vc.Add(await ct.Customer.AsNoTracking().Where(x => x.Id == o.CustomerId).Select(x => x.Name).FirstOrDefaultAsync(), "customer", o.CustomerId); + } + o.CustomerViz = vc.Get("customer", o.CustomerId); + } //////////////////////////////////////////////////////////////////////////////////////////////// // IMPORT EXPORT diff --git a/server/models/GZCase.cs b/server/models/GZCase.cs index 5d8bc73..671a553 100644 --- a/server/models/GZCase.cs +++ b/server/models/GZCase.cs @@ -19,6 +19,9 @@ namespace Sockeye.Models [Required] public string Name { get; set; } public string Notes { get; set; } + public long? CustomerId { get; set; } + [NotMapped] + public string CustomerViz { get; set; } public string Wiki { get; set; } public List Tags { get; set; } diff --git a/server/util/AySchema.cs b/server/util/AySchema.cs index 2f256cd..25bc957 100644 --- a/server/util/AySchema.cs +++ b/server/util/AySchema.cs @@ -907,7 +907,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); await ExecQueryAsync("CREATE TABLE agzcase (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, caseid BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, " + "created TIMESTAMPTZ NOT NULL, closed TIMESTAMPTZ, name TEXT NOT NULL, notes TEXT, " - + "wiki TEXT, tags VARCHAR(255) ARRAY )"); + + "wiki TEXT, tags VARCHAR(255) ARRAY, customerid BIGINT REFERENCES acustomer(id) )");