diff --git a/InterfaceToJira/InterfaceToJira.projitems b/InterfaceToJira/InterfaceToJira.projitems index 3d20ef0..2568089 100644 --- a/InterfaceToJira/InterfaceToJira.projitems +++ b/InterfaceToJira/InterfaceToJira.projitems @@ -32,6 +32,8 @@ + + diff --git a/InterfaceToJira/RestApiClient2/JiraAPIClient.cs b/InterfaceToJira/RestApiClient2/JiraAPIClient.cs index ef68682..068978b 100644 --- a/InterfaceToJira/RestApiClient2/JiraAPIClient.cs +++ b/InterfaceToJira/RestApiClient2/JiraAPIClient.cs @@ -2,6 +2,7 @@ using HIC.Common.InterfaceToJira.JIRA.RestApiClient2; using InterfaceToJira.RestApiClient2; using InterfaceToJira.RestApiClient2.JiraModel; +using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using NPOI.SS.UserModel; using RestSharp; @@ -64,9 +65,20 @@ public JiraAPIClient(JiraAccount account) } } - public List GetAllProjectAssets() + public JiraModel.AssetResponse GetProjectAsset(int id) { + var request = new RestRequest + { + Resource = $"/jsm/assets/workspace/{_workspaceID}/v1/object/{id}", + Method = Method.Get, + }; + var response = RESTHelper.Execute(client, request); + return response; + } + public List GetAllProjectAssets() + { + List assets = new(); var request = new RestRequest { Resource = $"/jsm/assets/workspace/{_workspaceID}/v1/object/aql", @@ -74,6 +86,23 @@ public List GetAllProjectAssets() RequestFormat = DataFormat.Json, }; request.AddBody("{\"qlQuery\": \"objectType = Project\"}"); - return RESTHelper.Execute>(client, request); + + var response = RESTHelper.Execute(client, request); + int total = response.total; + assets.AddRange(response.values); + while(total > assets.Count) { + //go get the rest + request = new RestRequest + { + Resource = $"/jsm/assets/workspace/{_workspaceID}/v1/object/aql?startAt={assets.Count+1}", + Method = Method.Post, + RequestFormat = DataFormat.Json, + }; + request.AddBody("{\"qlQuery\": \"objectType = Project\"}"); + + var additioanlResponse = RESTHelper.Execute(client, request); + assets.AddRange(additioanlResponse.values); + } + return assets.ToList(); } } diff --git a/InterfaceToJira/RestApiClient2/JiraModel/AQLResponse.cs b/InterfaceToJira/RestApiClient2/JiraModel/AQLResponse.cs new file mode 100644 index 0000000..91c46ca --- /dev/null +++ b/InterfaceToJira/RestApiClient2/JiraModel/AQLResponse.cs @@ -0,0 +1,190 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace InterfaceToJira.RestApiClient2.JiraModel; + + +public class AQLResponse +{ + public int startAt { get; set; } + public int maxResults { get; set; } + public int total { get; set; } + public bool isLast { get; set; } + public List values { get; set; } + public List objectTypeAttributes { get; set; } +} + +// Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse); +public class Attribute +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string objectTypeAttributeId { get; set; } + public List objectAttributeValues { get; set; } + public string objectId { get; set; } +} + +public class Avatar +{ + public string workspaceId { get; set; } + public string url16 { get; set; } + public string url48 { get; set; } + public string url72 { get; set; } + public string url144 { get; set; } + public string url288 { get; set; } + public string objectId { get; set; } + public MediaClientConfig mediaClientConfig { get; set; } +} + +public class DefaultType +{ + public int id { get; set; } + public string name { get; set; } +} + +public class Icon +{ + public string id { get; set; } + public string name { get; set; } + public string url16 { get; set; } + public string url48 { get; set; } +} + +public class Links +{ + public string self { get; set; } +} + +public class MediaClientConfig +{ + public string clientId { get; set; } + public string mediaBaseUrl { get; set; } + public string mediaJwtToken { get; set; } + public string fileId { get; set; } +} + +public class ObjectAttributeValue +{ + public object value { get; set; } + public string displayValue { get; set; } + public object searchValue { get; set; } + public bool referencedType { get; set; } + public ReferencedObject referencedObject { get; set; } +} + +public class ObjectType +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string name { get; set; } + public int type { get; set; } + public string description { get; set; } + public Icon icon { get; set; } + public int position { get; set; } + public DateTime created { get; set; } + public DateTime updated { get; set; } + public int objectCount { get; set; } + public string objectSchemaId { get; set; } + public bool inherited { get; set; } + public bool abstractObjectType { get; set; } + public bool parentObjectTypeInherited { get; set; } +} + +public class ObjectTypeAttribute +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public ObjectType objectType { get; set; } + public string name { get; set; } + public bool label { get; set; } + public DefaultType defaultType { get; set; } + public bool editable { get; set; } + public bool system { get; set; } + public bool sortable { get; set; } + public bool summable { get; set; } + public bool indexed { get; set; } + public int minimumCardinality { get; set; } + public int maximumCardinality { get; set; } + public bool removable { get; set; } + public bool hidden { get; set; } + public bool includeChildObjectTypes { get; set; } + public bool uniqueAttribute { get; set; } + public string options { get; set; } + public int position { get; set; } + public string description { get; set; } + public string suffix { get; set; } + public string regexValidation { get; set; } + public ReferenceType referenceType { get; set; } + public string referenceObjectTypeId { get; set; } + public ReferenceObjectType referenceObjectType { get; set; } +} + +public class ReferencedObject +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string label { get; set; } + public string objectKey { get; set; } + public Avatar avatar { get; set; } + public ObjectType objectType { get; set; } + public DateTime created { get; set; } + public DateTime updated { get; set; } + public bool hasAvatar { get; set; } + public long timestamp { get; set; } + public Links _links { get; set; } + public string name { get; set; } +} + +public class ReferenceObjectType +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string name { get; set; } + public Icon icon { get; set; } + public int position { get; set; } + public DateTime created { get; set; } + public DateTime updated { get; set; } + public int objectCount { get; set; } + public string objectSchemaId { get; set; } + public bool inherited { get; set; } + public bool abstractObjectType { get; set; } + public bool parentObjectTypeInherited { get; set; } +} + +public class ReferenceType +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string name { get; set; } + public string description { get; set; } + public string color { get; set; } + public string url16 { get; set; } + public bool removable { get; set; } +} + + +public class Value +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string label { get; set; } + public string objectKey { get; set; } + public Avatar avatar { get; set; } + public ObjectType objectType { get; set; } + public DateTime created { get; set; } + public DateTime updated { get; set; } + public bool hasAvatar { get; set; } + public long timestamp { get; set; } + public List attributes { get; set; } + public Links _links { get; set; } + public string name { get; set; } +} + diff --git a/InterfaceToJira/RestApiClient2/JiraModel/AssetResponse.cs b/InterfaceToJira/RestApiClient2/JiraModel/AssetResponse.cs new file mode 100644 index 0000000..84c8a8d --- /dev/null +++ b/InterfaceToJira/RestApiClient2/JiraModel/AssetResponse.cs @@ -0,0 +1,187 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace InterfaceToJira.RestApiClient2.JiraModel; + +// Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse); + + +public class AssetResponse +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string label { get; set; } + public string objectKey { get; set; } + public AssetResponseAvatar avatar { get; set; } + public AssetResponseObjectType objectType { get; set; } + public DateTime created { get; set; } + public DateTime updated { get; set; } + public bool hasAvatar { get; set; } + public long timestamp { get; set; } + public List attributes { get; set; } + public ExtendedInfo extendedInfo { get; set; } + public AssetResponseLinks _links { get; set; } + public string name { get; set; } +} + +public class AssetResponseAttribute +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public ObjectTypeAttribute objectTypeAttribute { get; set; } + public string objectTypeAttributeId { get; set; } + public List objectAttributeValues { get; set; } + public string objectId { get; set; } +} + +public class AssetResponseAvatar +{ + public string workspaceId { get; set; } + public string url16 { get; set; } + public string url48 { get; set; } + public string url72 { get; set; } + public string url144 { get; set; } + public string url288 { get; set; } + public string objectId { get; set; } + public MediaClientConfig mediaClientConfig { get; set; } +} + +public class AssetResponseDefaultType +{ + public int id { get; set; } + public string name { get; set; } +} + +public class ExtendedInfo +{ + public bool openIssuesExists { get; set; } + public bool attachmentsExists { get; set; } +} + +public class AssetResponseIcon +{ + public string id { get; set; } + public string name { get; set; } + public string url16 { get; set; } + public string url48 { get; set; } +} + +public class AssetResponseLinks +{ + public string self { get; set; } +} + +public class AssetResponseMediaClientConfig +{ + public string clientId { get; set; } + public string mediaBaseUrl { get; set; } + public string mediaJwtToken { get; set; } + public string fileId { get; set; } +} + +public class AssetResponseObjectAttributeValue +{ + public object value { get; set; } + public string displayValue { get; set; } + public object searchValue { get; set; } + public bool referencedType { get; set; } + public ReferencedObject referencedObject { get; set; } +} + +public class AssetResponseObjectType +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string name { get; set; } + public string description { get; set; } + public Icon icon { get; set; } + public int position { get; set; } + public DateTime created { get; set; } + public DateTime updated { get; set; } + public int objectCount { get; set; } + public string objectSchemaId { get; set; } + public bool inherited { get; set; } + public bool abstractObjectType { get; set; } + public bool parentObjectTypeInherited { get; set; } +} + +public class AssetResponseObjectTypeAttribute +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string name { get; set; } + public bool label { get; set; } + public DefaultType defaultType { get; set; } + public bool editable { get; set; } + public bool system { get; set; } + public bool sortable { get; set; } + public bool summable { get; set; } + public bool indexed { get; set; } + public int minimumCardinality { get; set; } + public int maximumCardinality { get; set; } + public bool removable { get; set; } + public bool hidden { get; set; } + public bool includeChildObjectTypes { get; set; } + public bool uniqueAttribute { get; set; } + public string options { get; set; } + public int position { get; set; } + public string description { get; set; } + public string suffix { get; set; } + public string regexValidation { get; set; } + public ReferenceType referenceType { get; set; } + public string referenceObjectTypeId { get; set; } + public ReferenceObjectType referenceObjectType { get; set; } +} + +public class AssetResponseReferencedObject +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string label { get; set; } + public string objectKey { get; set; } + public Avatar avatar { get; set; } + public ObjectType objectType { get; set; } + public DateTime created { get; set; } + public DateTime updated { get; set; } + public bool hasAvatar { get; set; } + public long timestamp { get; set; } + public Links _links { get; set; } + public string name { get; set; } +} + +public class AssetResponseReferenceObjectType +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string name { get; set; } + public Icon icon { get; set; } + public int position { get; set; } + public DateTime created { get; set; } + public DateTime updated { get; set; } + public int objectCount { get; set; } + public string objectSchemaId { get; set; } + public bool inherited { get; set; } + public bool abstractObjectType { get; set; } + public bool parentObjectTypeInherited { get; set; } +} + +public class AssetResponseReferenceType +{ + public string workspaceId { get; set; } + public string globalId { get; set; } + public string id { get; set; } + public string name { get; set; } + public string description { get; set; } + public string color { get; set; } + public string url16 { get; set; } + public bool removable { get; set; } +} + + diff --git a/InterfaceToJira/RestApiClient2/JiraModel/JiraAsset.cs b/InterfaceToJira/RestApiClient2/JiraModel/JiraAsset.cs index 88f07cf..2ae7257 100644 --- a/InterfaceToJira/RestApiClient2/JiraModel/JiraAsset.cs +++ b/InterfaceToJira/RestApiClient2/JiraModel/JiraAsset.cs @@ -11,5 +11,10 @@ public class JiraAsset public int id { get; set; } public string label { get; set; } public string objectKey { get; set; } + + public override string ToString() + { + return $"{objectKey}:{label}"; + } } } diff --git a/JiraPlugin.UI/CommandExecution/AtomicCommands/ExecuteCommandLinkProjectToJiraAsset.cs b/JiraPlugin.UI/CommandExecution/AtomicCommands/ExecuteCommandLinkProjectToJiraAsset.cs index 2cabfe1..e879eec 100644 --- a/JiraPlugin.UI/CommandExecution/AtomicCommands/ExecuteCommandLinkProjectToJiraAsset.cs +++ b/JiraPlugin.UI/CommandExecution/AtomicCommands/ExecuteCommandLinkProjectToJiraAsset.cs @@ -9,8 +9,8 @@ namespace JiraPlugin.UI.CommandExecution.AtomicCommands; public class ExecuteCommandLinkProjectToJiraAsset: BasicCommandExecution, IAtomicCommand { - private IActivateItems _activator; - private Project _project; + private readonly IActivateItems _activator; + private readonly Project _project; public ExecuteCommandLinkProjectToJiraAsset(IBasicActivateItems activator, Project project) { _activator = activator as IActivateItems; _project = project; diff --git a/JiraPlugin.UI/CommandExecution/AtomicCommands/ExecuteCommandViewLinkedExternalAssetsForProject.cs b/JiraPlugin.UI/CommandExecution/AtomicCommands/ExecuteCommandViewLinkedExternalAssetsForProject.cs new file mode 100644 index 0000000..5a83a4b --- /dev/null +++ b/JiraPlugin.UI/CommandExecution/AtomicCommands/ExecuteCommandViewLinkedExternalAssetsForProject.cs @@ -0,0 +1,25 @@ +using JiraPlugin.UI.JiraUI; +using Rdmp.Core.CommandExecution; +using Rdmp.Core.CommandExecution.AtomicCommands; +using Rdmp.Core.DataExport.Data; +using Rdmp.UI.ItemActivation; + +namespace JiraPlugin.UI.CommandExecution.AtomicCommands; + +public class ExecuteCommandViewLinkedExternalAssetsForProject: BasicCommandExecution, IAtomicCommand +{ + + private readonly IActivateItems _activator; + private readonly Project _project; + + public ExecuteCommandViewLinkedExternalAssetsForProject(IBasicActivateItems activator, Project project) { + _activator = activator as IActivateItems; + _project = project; + } + + public override void Execute() + { + base.Execute(); + _activator.Activate(_project); + } +} diff --git a/JiraPlugin.UI/CommandExecution/JiraPluginMenu.cs b/JiraPlugin.UI/CommandExecution/JiraPluginMenu.cs index 9307e78..407e4e4 100644 --- a/JiraPlugin.UI/CommandExecution/JiraPluginMenu.cs +++ b/JiraPlugin.UI/CommandExecution/JiraPluginMenu.cs @@ -19,7 +19,10 @@ public override IEnumerable GetAdditionalRightClickMenuItems(obj { if (_activator != null && o is Project) { - return new[] { new ExecuteCommandLinkProjectToJiraAsset(_activator,(Project)o) }; + return [ + new ExecuteCommandLinkProjectToJiraAsset(_activator,(Project)o), + new ExecuteCommandViewLinkedExternalAssetsForProject(_activator,(Project)o) + ]; } return base.GetAdditionalRightClickMenuItems(o); diff --git a/JiraPlugin.UI/JiraUI/LinkProjectToJiraAssetUI.Designer.cs b/JiraPlugin.UI/JiraUI/LinkProjectToJiraAssetUI.Designer.cs index 98da8ce..deb1355 100644 --- a/JiraPlugin.UI/JiraUI/LinkProjectToJiraAssetUI.Designer.cs +++ b/JiraPlugin.UI/JiraUI/LinkProjectToJiraAssetUI.Designer.cs @@ -31,15 +31,18 @@ private void InitializeComponent() cbJiraConfiguration = new ComboBox(); label1 = new Label(); label2 = new Label(); - cbAssets = new ComboBox(); lblError = new Label(); + cbAssets = new ComboBox(); + label3 = new Label(); + cbProject = new ComboBox(); + button1 = new Button(); SuspendLayout(); // // cbJiraConfiguration // cbJiraConfiguration.Enabled = false; cbJiraConfiguration.FormattingEnabled = true; - cbJiraConfiguration.Location = new Point(138, 31); + cbJiraConfiguration.Location = new Point(138, 51); cbJiraConfiguration.Name = "cbJiraConfiguration"; cbJiraConfiguration.Size = new Size(242, 23); cbJiraConfiguration.TabIndex = 0; @@ -48,7 +51,7 @@ private void InitializeComponent() // label1 // label1.AutoSize = true; - label1.Location = new Point(31, 34); + label1.Location = new Point(31, 54); label1.Name = "label1"; label1.Size = new Size(101, 15); label1.TabIndex = 1; @@ -57,41 +60,73 @@ private void InitializeComponent() // label2 // label2.AutoSize = true; - label2.Location = new Point(77, 87); + label2.Location = new Point(77, 107); label2.Name = "label2"; label2.Size = new Size(55, 15); label2.TabIndex = 2; label2.Text = "Jira Asset"; // - // cbAssets - // - cbAssets.AutoCompleteSource = AutoCompleteSource.ListItems; - cbAssets.DropDownStyle = ComboBoxStyle.DropDownList; - cbAssets.Enabled = false; - cbAssets.FormattingEnabled = true; - cbAssets.Location = new Point(138, 84); - cbAssets.Name = "cbAssets"; - cbAssets.Size = new Size(242, 23); - cbAssets.TabIndex = 3; - // // lblError // lblError.AutoSize = true; lblError.Font = new Font("Segoe UI", 12F); lblError.ForeColor = Color.Red; - lblError.Location = new Point(40, 131); + lblError.Location = new Point(31, 177); lblError.Name = "lblError"; lblError.Size = new Size(52, 21); lblError.TabIndex = 4; lblError.Text = "label3"; lblError.Visible = false; // + // cbAssets + // + cbAssets.Enabled = false; + cbAssets.FormattingEnabled = true; + cbAssets.Location = new Point(138, 104); + cbAssets.Name = "cbAssets"; + cbAssets.Size = new Size(242, 23); + cbAssets.TabIndex = 5; + cbAssets.SelectedIndexChanged += cbAssets_SelectedIndexChanged; + cbAssets.TextChanged += cbAssets_TextChanged; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(88, 13); + label3.Name = "label3"; + label3.Size = new Size(44, 15); + label3.TabIndex = 6; + label3.Text = "Project"; + // + // cbProject + // + cbProject.Enabled = false; + cbProject.FormattingEnabled = true; + cbProject.Location = new Point(138, 10); + cbProject.Name = "cbProject"; + cbProject.Size = new Size(242, 23); + cbProject.TabIndex = 7; + // + // button1 + // + button1.Enabled = false; + button1.Location = new Point(249, 148); + button1.Name = "button1"; + button1.Size = new Size(131, 23); + button1.TabIndex = 8; + button1.Text = "Link External Asset"; + button1.UseVisualStyleBackColor = true; + button1.Click += button1_Click; + // // LinkProjectToJiraAssetUI // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - Controls.Add(lblError); + Controls.Add(button1); + Controls.Add(cbProject); + Controls.Add(label3); Controls.Add(cbAssets); + Controls.Add(lblError); Controls.Add(label2); Controls.Add(label1); Controls.Add(cbJiraConfiguration); @@ -106,6 +141,9 @@ private void InitializeComponent() private ComboBox cbJiraConfiguration; private Label label1; private Label label2; - private ComboBox cbAssets; private Label lblError; + private ComboBox cbAssets; + private Label label3; + private ComboBox cbProject; + private Button button1; } diff --git a/JiraPlugin.UI/JiraUI/LinkProjectToJiraAssetUI.cs b/JiraPlugin.UI/JiraUI/LinkProjectToJiraAssetUI.cs index a60ad35..a94ffad 100644 --- a/JiraPlugin.UI/JiraUI/LinkProjectToJiraAssetUI.cs +++ b/JiraPlugin.UI/JiraUI/LinkProjectToJiraAssetUI.cs @@ -7,14 +7,19 @@ using InterfaceToJira.RestApiClient2; using HIC.Common.InterfaceToJira.JIRA.RestApiClient2; using HIC.Common.InterfaceToJira; +using InterfaceToJira.RestApiClient2.JiraModel; +using Rdmp.Core.Curation; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace JiraPlugin.UI.JiraUI; public partial class LinkProjectToJiraAssetUI : LinkProjectToJiraAssetUI_Design { + private IActivateItems _activator; private Project _project; private TicketingSystemConfiguration _ticketingSystemConfiguration; private JiraAPIClient _client; + private List _jiraProjects; public LinkProjectToJiraAssetUI() { InitializeComponent(); @@ -22,6 +27,7 @@ public LinkProjectToJiraAssetUI() public override void SetDatabaseObject(IActivateItems activator, Project databaseObject) { + _activator = activator; _project = databaseObject; var jiraAccounts = activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere("Type", "JiraPlugin.JIRATicketingSystem"); if (!jiraAccounts.Any()) @@ -35,6 +41,8 @@ public override void SetDatabaseObject(IActivateItems activator, Project databas cbJiraConfiguration.Items.AddRange(jiraAccounts); cbJiraConfiguration.Enabled = true; + cbProject.Text = _project.Name; + } public override string GetTabName() => $"Link Project to Jira Asset"; @@ -42,13 +50,6 @@ public override void SetDatabaseObject(IActivateItems activator, Project databas private void cbJiraConfiguration_SelectedIndexChanged(object sender, EventArgs e) { _ticketingSystemConfiguration = (TicketingSystemConfiguration)cbJiraConfiguration.Items[cbJiraConfiguration.SelectedIndex]; - //var jiraAccount = new JiraAccount(new HIC.Common.InterfaceToJira.JiraApiConfiguration() - //{ - // ServerUrl = _ticketingSystemConfiguration.Url, - // User = _ticketingSystemConfiguration.DataAccessCredentials.Username, - // Password = _ticketingSystemConfiguration.DataAccessCredentials.GetDecryptedPassword(), - //}); - //_client = new JiraAPIClient(jiraAccount); _client ??= new JiraAPIClient(new JiraAccount(new JiraApiConfiguration { ServerUrl = _ticketingSystemConfiguration.Url, @@ -56,15 +57,40 @@ private void cbJiraConfiguration_SelectedIndexChanged(object sender, EventArgs e Password = _ticketingSystemConfiguration.DataAccessCredentials.GetDecryptedPassword(), ApiUrl = _ticketingSystemConfiguration.Url })); - var projects = _client.GetAllProjectAssets(); + _jiraProjects = _client.GetAllProjectAssets(); cbAssets.Items.Clear(); - cbAssets.Items.Add(projects); + cbAssets.Items.AddRange(_jiraProjects.ToArray()); cbAssets.Enabled = true; + + if(cbAssets.SelectedIndex != null) + { + button1.Enabled = true; + } + } + + private void cbAssets_TextChanged(object sender, EventArgs e) + { + //var txt = cbAssets.Text.ToLower(); + //var matchs = _jiraProjects.Where(p => p.ToString().ToLower().Contains(txt)); + //cbAssets.Items.Clear(); + //cbAssets.Items.AddRange(matchs.ToArray()); + //cbAssets.DroppedDown = true; + //Cursor.Current = Cursors.Default; + //cbAssets.Select(txt.Length, 0); } -} + private void cbAssets_SelectedIndexChanged(object sender, EventArgs e) + { + + } -//[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider))] -//public abstract class LinkProjectToJiraAssetUI_Design : RDMPSingleDatabaseObjectControl -//{ -//} \ No newline at end of file + private void button1_Click(object sender, EventArgs e) + { + var selectedAsset = _jiraProjects[cbAssets.SelectedIndex]; + var asset = new ExternalAsset(_activator.RepositoryLocator.CatalogueRepository, selectedAsset.ToString(), selectedAsset.id, _ticketingSystemConfiguration.ID, _project.GetType().ToString(), _project.ID); + asset.SaveToDatabase(); + //todo close the user control + _activator.Show("External asset successfully linked with the project."); + + } +} \ No newline at end of file diff --git a/JiraPlugin.UI/JiraUI/ViewProjectJiraAssets.Designer.cs b/JiraPlugin.UI/JiraUI/ViewProjectJiraAssets.Designer.cs new file mode 100644 index 0000000..1640458 --- /dev/null +++ b/JiraPlugin.UI/JiraUI/ViewProjectJiraAssets.Designer.cs @@ -0,0 +1,62 @@ +namespace JiraPlugin.UI.JiraUI +{ + partial class ViewProjectJiraAssets + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView1 = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // dataGridView1 + // + dataGridView1.AllowUserToAddRows = false; + dataGridView1.AllowUserToDeleteRows = false; + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Location = new Point(3, 15); + dataGridView1.Name = "dataGridView1"; + dataGridView1.ReadOnly = true; + dataGridView1.Size = new Size(795, 263); + dataGridView1.TabIndex = 0; + dataGridView1.CellContentClick += dataGridView1_CellContentClick; + // + // ViewProjectJiraAssets + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(dataGridView1); + Name = "ViewProjectJiraAssets"; + Size = new Size(812, 461); + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView1; + } +} diff --git a/JiraPlugin.UI/JiraUI/ViewProjectJiraAssets.cs b/JiraPlugin.UI/JiraUI/ViewProjectJiraAssets.cs new file mode 100644 index 0000000..b92fb64 --- /dev/null +++ b/JiraPlugin.UI/JiraUI/ViewProjectJiraAssets.cs @@ -0,0 +1,89 @@ +using HIC.Common.InterfaceToJira.JIRA.RestApiClient2; +using HIC.Common.InterfaceToJira; +using InterfaceToJira.RestApiClient2; +using InterfaceToJira.RestApiClient2.JiraModel; +using Rdmp.Core.Curation; +using Rdmp.Core.Curation.Data; +using Rdmp.Core.DataExport.Data; +using Rdmp.UI.ItemActivation; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Rdmp.Core.ReusableLibraryCode; + +namespace JiraPlugin.UI.JiraUI +{ + public partial class ViewProjectJiraAssets : LinkProjectToJiraAssetUI_Design + { + + private List _externalAssets; + private List _jiraAssets; + private JiraAPIClient _client; + public ViewProjectJiraAssets() + { + InitializeComponent(); + } + + + public override void SetDatabaseObject(IActivateItems activator, Project databaseObject) + { + base.SetDatabaseObject(activator, databaseObject); + _externalAssets = activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere("ObjectID", databaseObject.ID).Where(ea => ea.ObjectType == typeof(Project).ToString()).ToList(); + DataTable dt = new(); + dt.Columns.Add("Name"); + dt.Columns.Add("URL"); + //dt.Columns.Add("Link"); + foreach (var asset in _externalAssets) + { + var ticketingSystemConfiguration = activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere("ID", asset.TicketingConfiguration_ID).FirstOrDefault(); + if (ticketingSystemConfiguration is null) + { + throw new Exception("Unable to find ticketing system"); + } + _client ??= new JiraAPIClient(new JiraAccount(new JiraApiConfiguration + { + ServerUrl = ticketingSystemConfiguration.Url, + User = ticketingSystemConfiguration.DataAccessCredentials.Username, + Password = ticketingSystemConfiguration.DataAccessCredentials.GetDecryptedPassword(), + ApiUrl = ticketingSystemConfiguration.Url + })); + var jiraAsset = _client.GetProjectAsset(asset.ExternalAsset_ID); + var url = $"{ticketingSystemConfiguration.Url}/jira/servicedesk/assets/object-schema/3?typeId={jiraAsset.objectType.id}&view=list&objectId={jiraAsset.id}"; + dt.Rows.Add(asset.Name, url); + } + dataGridView1.DataSource = dt; + + DataGridViewButtonColumn button = new DataGridViewButtonColumn(); + { + button.Name = "View"; + button.HeaderText = "View"; + button.Text = "View"; + button.UseColumnTextForButtonValue = true; //dont forget this line + this.dataGridView1.Columns.Add(button); + } + dataGridView1.CellClick += dataGridView1_CellClick; + + dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); + } + + private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.ColumnIndex == dataGridView1.Columns["view"].Index) + { + string selectedValue = dataGridView1.Rows[e.RowIndex].Cells["URL"].Value.ToString(); + UsefulStuff.OpenUrl(selectedValue); + } + } + + private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + } +} diff --git a/JiraPlugin.UI/JiraUI/ViewProjectJiraAssets.resx b/JiraPlugin.UI/JiraUI/ViewProjectJiraAssets.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/JiraPlugin.UI/JiraUI/ViewProjectJiraAssets.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RDMP b/RDMP index f6474f2..3f48b57 160000 --- a/RDMP +++ b/RDMP @@ -1 +1 @@ -Subproject commit f6474f2e0dc1d0e93c7c07b18bf2c8dadb3c829f +Subproject commit 3f48b573eefa0e7d5f5a47355f90728ec7984597