Skip to content

Commit

Permalink
Fix for GitHub Issue 201
Browse files Browse the repository at this point in the history
  • Loading branch information
juileetikekar committed Jul 31, 2024
1 parent c404e15 commit bdcc80b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 96 deletions.
17 changes: 14 additions & 3 deletions src/AasxCsharpLibrary/Extensions/ExtendLangString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@ public static string GetDefaultStringGen<T>(List<T> langStrings, string defaultL

// search
foreach (var ls in langStrings)
if (ls.Language.Trim().ToLower() == defaultLang)
res = ls.Text;
{
if (ls != null)
{
if (ls.Language.Trim().ToLower() == defaultLang)
res = ls.Text;
}
}

if (res == null && langStrings.Count > 0)
res = langStrings[0].Text;
{
if (langStrings[0] != null)
{
res = langStrings[0].Text;
}
}

// found?
return res;
Expand Down
140 changes: 72 additions & 68 deletions src/AasxPackageLogic/DispEditHelperBasics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This source code may use other Open Source software components (see LICENSE.txt)
using AasxPackageLogic.PackageCentral;
using AdminShellNS;
using AdminShellNS.DiaryData;
using AdminShellNS.Extensions;
using AnyUi;
using Extensions;
using Newtonsoft.Json;
Expand Down Expand Up @@ -827,7 +828,7 @@ public void AddKeyListLangStr<T>(
}

// contents?
if (langStr != null)
if (!langStr.IsNullOrEmpty())
for (int i = 0; i < langStr.Count; i++)
if (repo == null)
{
Expand All @@ -850,74 +851,77 @@ public void AddKeyListLangStr<T>(
// save in current context
var currentI = 0 + i;

// lang
var tbLang = AddSmallComboBoxTo(
g, 0 + i + rowOfs, 1,
margin: NormalOrCapa(
new AnyUiThickness(4, 2, 2, 2),
AnyUiContextCapability.Blazor, new AnyUiThickness(4, 2, 2, 0)),
padding: NormalOrCapa(
new AnyUiThickness(0, -1, 0, -1),
AnyUiContextCapability.Blazor, new AnyUiThickness(0, 4, 0, 4)),
text: "" + langStr[currentI].Language,
minWidth: 60,
items: defaultLanguages,
isEditable: true);
AnyUiUIElement.RegisterControl(
tbLang,
(o) =>
{
langStr[currentI].Language = o as string;
emitCustomEvent?.Invoke(relatedReferable);
return new AnyUiLambdaActionNone();
});
// check here, if to hightlight
if (tbLang != null && this.highlightField != null &&
this.highlightField.fieldHash == langStr[currentI].Language.GetHashCode() &&
//(this.highlightField.containingObject == langStr[currentI]))
//TODO (jtikekar, 0000-00-00): need to test
CompareUtils.Compare<IAbstractLangString>((IAbstractLangString)this.highlightField.containingObject, langStr[currentI]))
this.HighligtStateElement(tbLang, true);

// str
var tbStr = AddSmallTextBoxTo(
g, 0 + i + rowOfs, 2,
margin: NormalOrCapa(
new AnyUiThickness(2, 2, 2, 2),
AnyUiContextCapability.Blazor, new AnyUiThickness(6, 2, 2, 2)),
verticalAlignment: AnyUiVerticalAlignment.Center,
verticalContentAlignment: AnyUiVerticalAlignment.Center,
text: "" + langStr[currentI].Text);
AnyUiUIElement.RegisterControl(
tbStr,
(o) =>
{
langStr[currentI].Text = o as string;
emitCustomEvent?.Invoke(relatedReferable);
return new AnyUiLambdaActionNone();
});
// check here, if to hightlight
if (tbStr != null && this.highlightField != null &&
this.highlightField.fieldHash == langStr[currentI].Text.GetHashCode() &&
//(this.highlightField.containingObject == langStr[currentI]))
//TODO (jtikekar, 0000-00-00): need to test
CompareUtils.Compare<IAbstractLangString>((IAbstractLangString)this.highlightField.containingObject, langStr[currentI]))
this.HighligtStateElement(tbStr, true);

// button [-]
AnyUiUIElement.RegisterControl(
AddSmallButtonTo(
g, 0 + i + rowOfs, 3,
margin: new AnyUiThickness(2, 2, 2, 2),
padding: new AnyUiThickness(5, 0, 5, 0),
if (langStr[currentI] != null)
{
// lang
var tbLang = AddSmallComboBoxTo(
g, 0 + i + rowOfs, 1,
margin: NormalOrCapa(
new AnyUiThickness(4, 2, 2, 2),
AnyUiContextCapability.Blazor, new AnyUiThickness(4, 2, 2, 0)),
padding: NormalOrCapa(
new AnyUiThickness(0, -1, 0, -1),
AnyUiContextCapability.Blazor, new AnyUiThickness(0, 4, 0, 4)),
text: "" + langStr[currentI].Language,
minWidth: 60,
items: defaultLanguages,
isEditable: true);
AnyUiUIElement.RegisterControl(
tbLang,
(o) =>
{
langStr[currentI].Language = o as string;
emitCustomEvent?.Invoke(relatedReferable);
return new AnyUiLambdaActionNone();
});
// check here, if to hightlight
if (tbLang != null && this.highlightField != null &&
this.highlightField.fieldHash == langStr[currentI].Language.GetHashCode() &&
//(this.highlightField.containingObject == langStr[currentI]))
//TODO (jtikekar, 0000-00-00): need to test
CompareUtils.Compare<IAbstractLangString>((IAbstractLangString)this.highlightField.containingObject, langStr[currentI]))
this.HighligtStateElement(tbLang, true);

// str
var tbStr = AddSmallTextBoxTo(
g, 0 + i + rowOfs, 2,
margin: NormalOrCapa(
new AnyUiThickness(2, 2, 2, 2),
AnyUiContextCapability.Blazor, new AnyUiThickness(6, 2, 2, 2)),
verticalAlignment: AnyUiVerticalAlignment.Center,
content: "-"),
(o) =>
{
langStr.RemoveAt(currentI);
emitCustomEvent?.Invoke(relatedReferable);
return new AnyUiLambdaActionRedrawEntity();
});
verticalContentAlignment: AnyUiVerticalAlignment.Center,
text: "" + langStr[currentI].Text);
AnyUiUIElement.RegisterControl(
tbStr,
(o) =>
{
langStr[currentI].Text = o as string;
emitCustomEvent?.Invoke(relatedReferable);
return new AnyUiLambdaActionNone();
});
// check here, if to hightlight
if (tbStr != null && this.highlightField != null &&
this.highlightField.fieldHash == langStr[currentI].Text.GetHashCode() &&
//(this.highlightField.containingObject == langStr[currentI]))
//TODO (jtikekar, 0000-00-00): need to test
CompareUtils.Compare<IAbstractLangString>((IAbstractLangString)this.highlightField.containingObject, langStr[currentI]))
this.HighligtStateElement(tbStr, true);

// button [-]
AnyUiUIElement.RegisterControl(
AddSmallButtonTo(
g, 0 + i + rowOfs, 3,
margin: new AnyUiThickness(2, 2, 2, 2),
padding: new AnyUiThickness(5, 0, 5, 0),
verticalAlignment: AnyUiVerticalAlignment.Center,
content: "-"),
(o) =>
{
langStr.RemoveAt(currentI);
emitCustomEvent?.Invoke(relatedReferable);
return new AnyUiLambdaActionRedrawEntity();
});
}
}

// in total
Expand Down
3 changes: 3 additions & 0 deletions src/AasxPackageLogic/DispEditHelperEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2794,7 +2794,10 @@ public void DisplayOrEditAasEntitySubmodelElement(
{
var newcd = resCD;
if (null == env.FindConceptDescriptionByReference(new Aas.Reference(Aas.ReferenceTypes.ModelReference, new List<Aas.IKey>() { new Aas.Key(Aas.KeyTypes.ConceptDescription, newcd.Id) })))
{
env.ConceptDescriptions ??= new List<IConceptDescription>();
env.ConceptDescriptions.Add(newcd);
}
}
// set the semantic key
Expand Down
56 changes: 31 additions & 25 deletions src/AasxPackageLogic/EclassUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This source code may use other Open Source software components (see LICENSE.txt)
using Extensions;
using Microsoft.IdentityModel.Tokens;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.IO;
using System.Xml;
Expand Down Expand Up @@ -484,15 +485,15 @@ private static void FindChildLangStrings<T>(
if (ni.Attributes != null && ni.Attributes[langCodeAttrib] != null)
{
object ls = null;
if (typeof(T) is ILangStringTextType)
if (typeof(T) == typeof(ILangStringTextType))
{
ls = new LangStringTextType(ni.Attributes["language_code"].InnerText, ni.InnerText);
}
else if (typeof(T) is ILangStringPreferredNameTypeIec61360)
else if (typeof(T) == typeof(ILangStringPreferredNameTypeIec61360))
{
ls = new LangStringPreferredNameTypeIec61360(ni.Attributes["language_code"].InnerText, ni.InnerText);
}
else if (typeof(T) is ILangStringDefinitionTypeIec61360)
else if (typeof(T) == typeof(ILangStringDefinitionTypeIec61360))
{
ls = new LangStringDefinitionTypeIec61360(ni.Attributes["language_code"].InnerText, ni.InnerText);
}
Expand Down Expand Up @@ -626,30 +627,35 @@ public static Aas.ConceptDescription GenerateConceptDescription(
var found = false;
foreach (var pn in ds.PreferredName)
{
// let have "en" always have precedence!
if (found && !pn.Language.ToLower().Trim().Contains("en"))
continue;
// ok
found = true;
// Array of words
var words = pn.Text.Split(
new[] { ' ', '\t', '-', '_' },
StringSplitOptions.RemoveEmptyEntries);
var sn = "";
foreach (var w in words)
if (pn != null)
{
var part = w.ToLower().Trim();
if (part.Length > 3)
part = part.Substring(0, 3);
if (part.Length > 0)
part = Char.ToUpperInvariant(part[0]) + part.Substring(1);
sn += part;
// let have "en" always have precedence!
if (found && !pn.Language.ToLower().Trim().Contains("en"))
continue;
// ok
found = true;
// Array of words
var words = pn.Text.Split(
new[] { ' ', '\t', '-', '_' },
StringSplitOptions.RemoveEmptyEntries);
var sn = "";
foreach (var w in words)
{
var part = w.ToLower().Trim();
if (part.Length > 3)
part = part.Substring(0, 3);
if (part.Length > 0)
part = Char.ToUpperInvariant(part[0]) + part.Substring(1);
sn += part;
}
// set it
ds.ShortName ??= new List<ILangStringShortNameTypeIec61360>();
ds.ShortName.Add(new Aas.LangStringShortNameTypeIec61360(pn.Language, sn));
//ds.ShortName = new List<Aas.ILangStringShortNameTypeIec61360>
//{
// new Aas.LangStringShortNameTypeIec61360(AdminShellUtil.GetDefaultLngIso639(), sn)
//};
}
// set it
ds.ShortName = new List<Aas.ILangStringShortNameTypeIec61360>
{
new Aas.LangStringShortNameTypeIec61360(AdminShellUtil.GetDefaultLngIso639(), sn)
};
}
}
}
Expand Down

0 comments on commit bdcc80b

Please sign in to comment.