Skip to content

Commit

Permalink
Add endpoint in preview to get footer
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren committed May 23, 2024
1 parent 711228b commit 8ebc5bb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
8 changes: 6 additions & 2 deletions backend/src/Designer/Controllers/PreviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,16 @@ public IActionResult UpdateAttachmentWithTag(string org, string app, [FromQuery]
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="app">Application identifier which is unique within an organisation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
/// <returns>Empty response</returns>
[HttpGet]
[Route("api/v1/footer")]
public IActionResult Footer(string org, string app)
public async Task<IActionResult> Footer(string org, string app, CancellationToken cancellationToken)
{
return Ok();
string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
FooterFile footerFile = await altinnAppGitRepository.GetFooter(cancellationToken);
return Ok(footerFile);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class AltinnAppGitRepository : AltinnGitRepository
private const string LayoutSettingsFilename = "Settings.json";
private const string AppMetadataFilename = "applicationmetadata.json";
private const string LayoutSetsFilename = "layout-sets.json";
private const string FooterFilename = "footer.json";
private const string RuleHandlerFilename = "RuleHandler.js";
private const string RuleConfigurationFilename = "RuleConfiguration.json";
private const string ProcessDefinitionFilename = "process.bpmn";
Expand Down Expand Up @@ -598,6 +599,15 @@ public async Task SaveLayoutSets(LayoutSets layoutSets)
}
}

public async Task<FooterFile> GetFooter(CancellationToken cancellationToken = default)
{
string footerFilePath = GetPathToFooterFile();
cancellationToken.ThrowIfCancellationRequested();
string fileContent = await ReadTextByRelativePathAsync(footerFilePath, cancellationToken);
FooterFile footerFileFile = JsonSerializer.Deserialize<FooterFile>(fileContent, JsonOptions);
return footerFileFile;
}

/// <summary>
/// Saves the RuleHandler.js for a specific layout set
/// </summary>
Expand Down Expand Up @@ -838,6 +848,11 @@ private static string GetPathToLayoutSetsFile()
return Path.Combine(LayoutsFolderName, LayoutSetsFilename);
}

private static string GetPathToFooterFile()
{
return Path.Combine(LayoutsFolderName, FooterFilename);
}

private static string GetPathToRuleHandler(string layoutSetName)
{
return layoutSetName.IsNullOrEmpty() ?
Expand Down
28 changes: 28 additions & 0 deletions backend/src/Designer/Models/FooterFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Altinn.Studio.Designer.Models;

public class FooterFile
{
[JsonPropertyName("$schema")]
public string Schema { get; set; }

[JsonPropertyName("footer")]
public List<FooterConfig> Footer { get; set; }
}

public class FooterConfig
{
[JsonPropertyName("type")]
public string Type { get; set; }

[JsonPropertyName("icon")]
public string Icon { get; set; }

[JsonPropertyName("title")]
public string Title { get; set; }

[JsonPropertyName("target")]
public string Target { get; set; }
}

0 comments on commit 8ebc5bb

Please sign in to comment.