This commit is contained in:
@@ -179,7 +179,7 @@ namespace AyaNova.PlugIn.V8
|
||||
|
||||
/*
|
||||
TODO:
|
||||
*
|
||||
* Error should post somehow to server so can see at server what went wrong
|
||||
* custom fields processor for: User, Client, Contract, HeadOffice, LoanItem, part, project, purchaseorder, unit, unitmodel, vendor, workorderitem
|
||||
* See util.cs in winformapp for all custom field shit, lines 3114 is a good starting point
|
||||
*/
|
||||
@@ -348,8 +348,10 @@ namespace AyaNova.PlugIn.V8
|
||||
private async System.Threading.Tasks.Task ExportUsers(ProgressForm progress)
|
||||
{
|
||||
//Step 1: export the CustomFields to FormCustom if applicable so that when doing individual items we can export their custom data too
|
||||
var CustomFieldsToExport = await ExportCustomFieldSchema("User");
|
||||
var ocf=ObjectHasCustomFieldDataToExport("User");
|
||||
bool ShouldExportCustom = ocf != null;
|
||||
|
||||
var DateCustomFields = await ExportCustomFieldSchema(ocf, "User", "User");
|
||||
//Step 2: export the users
|
||||
|
||||
|
||||
@@ -405,6 +407,12 @@ namespace AyaNova.PlugIn.V8
|
||||
}
|
||||
SetTags(d, tags);
|
||||
|
||||
//Custom fields?
|
||||
if (ShouldExportCustom)
|
||||
{
|
||||
d.customFields = CustomFieldData(c);
|
||||
}
|
||||
|
||||
var a = await util.PostAsync("User", d.ToString());
|
||||
long RavenId = util.IdFromResponse(a);
|
||||
Map.Add(c.ID, RavenId);
|
||||
@@ -733,32 +741,56 @@ namespace AyaNova.PlugIn.V8
|
||||
|
||||
|
||||
|
||||
private async System.Threading.Tasks.Task<List<string>> ExportCustomFieldSchema(string objectName, string RavenCustomTranslationKeyObjectName = null)
|
||||
//export objects custom field data into jobject string
|
||||
private string CustomFieldData(object biz)
|
||||
{
|
||||
var ret = new List<string>();
|
||||
if (RavenCustomTranslationKeyObjectName == null) RavenCustomTranslationKeyObjectName = objectName;//i.e. WidgetCustom1, WidgetCustom2 etc
|
||||
dynamic d=new JObject();
|
||||
|
||||
//NOTE: this code stolen from winforApp::Util.cs PrepareCustomFieldsGrid method
|
||||
for (int x = 0; x < 10; x++)
|
||||
{
|
||||
object o = (object)biz.GetType().GetProperty("Custom"+x.ToString()).GetValue(biz, null);
|
||||
//if (o != null)
|
||||
// o = o.ToString();
|
||||
//JObject j = (JObject) JObject.FromObject(o);
|
||||
d["c"+(x+1).ToString()] = o.ToString();
|
||||
|
||||
//is there customizations designated for this object?
|
||||
ObjectCustomFields ocf = ObjectCustomFields.GetItems(objectName);
|
||||
}
|
||||
return d.ToString();
|
||||
}
|
||||
|
||||
static public ObjectCustomFields ObjectHasCustomFieldDataToExport(string sObject)
|
||||
{
|
||||
ObjectCustomFields ocf = ObjectCustomFields.GetItems(sObject);
|
||||
if (ocf.Count == 0)
|
||||
return ret;
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.formkey = RavenCustomTranslationKeyObjectName;
|
||||
dynamic dtemplate = new JArray();
|
||||
|
||||
bool bAtLeastOneFieldIsVisible = false;
|
||||
foreach (ObjectCustomField f in ocf)
|
||||
{
|
||||
if (f.Visible)
|
||||
{
|
||||
bAtLeastOneFieldIsVisible = true;
|
||||
ret.Add(f.FieldName);
|
||||
return ocf;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task<List<int>> ExportCustomFieldSchema(ObjectCustomFields ocf, string v7CustomFieldObjectName, string RavenCustomTranslationKeyObjectName)
|
||||
{
|
||||
var ret = new List<int>();
|
||||
|
||||
//NOTE: this code inspired by winforApp::Util.cs PrepareCustomFieldsGrid method
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.formkey = RavenCustomTranslationKeyObjectName;
|
||||
dynamic dtemplate = new JArray();
|
||||
|
||||
foreach (ObjectCustomField f in ocf)
|
||||
{
|
||||
if (f.Visible)
|
||||
{
|
||||
int n = Convert.ToInt32(f.FieldName.Replace("Custom", "")) + 1;//raven custom fields are 1 based, v7 are zero based
|
||||
CustomFieldLocaleKeys.Add(RavenCustomTranslationKeyObjectName + n.ToString(), util.LocaleText.GetLocalizedText(objectName + ".Label." + f.FieldName));
|
||||
CustomFieldLocaleKeys.Add(RavenCustomTranslationKeyObjectName + n.ToString(),
|
||||
util.LocaleText.GetLocalizedText(v7CustomFieldObjectName + ".Label." + f.FieldName));
|
||||
|
||||
dynamic dt = new JObject();
|
||||
dt.fld = RavenCustomTranslationKeyObjectName + "Custom" + n.ToString();
|
||||
@@ -771,9 +803,11 @@ namespace AyaNova.PlugIn.V8
|
||||
break;
|
||||
case FormFieldDataTypes.DateOnly:
|
||||
dt.type = util.AyaUiFieldDataType.Date;
|
||||
ret.Add(n-1);
|
||||
break;
|
||||
case FormFieldDataTypes.DateTime:
|
||||
dt.type = util.AyaUiFieldDataType.DateTime;
|
||||
ret.Add(n - 1);
|
||||
break;
|
||||
case FormFieldDataTypes.Number:
|
||||
dt.type = util.AyaUiFieldDataType.Decimal;
|
||||
@@ -783,6 +817,7 @@ namespace AyaNova.PlugIn.V8
|
||||
break;
|
||||
case FormFieldDataTypes.TimeOnly:
|
||||
dt.type = util.AyaUiFieldDataType.Time;
|
||||
ret.Add(n - 1);
|
||||
break;
|
||||
case FormFieldDataTypes.TrueFalse:
|
||||
dt.type = util.AyaUiFieldDataType.Bool;
|
||||
@@ -797,9 +832,7 @@ namespace AyaNova.PlugIn.V8
|
||||
}
|
||||
}
|
||||
|
||||
if (!bAtLeastOneFieldIsVisible)
|
||||
return ret;
|
||||
|
||||
|
||||
d.template = dtemplate.ToString();
|
||||
|
||||
//ok, were here because there *are* custom fields available
|
||||
|
||||
Reference in New Issue
Block a user