Skip to content

Commit

Permalink
Merge pull request #132 from signnow/prefill-text
Browse files Browse the repository at this point in the history
Edit Text field feature
  • Loading branch information
AlexNDRmac authored Jan 26, 2022
2 parents 76701f7 + bdd2a92 commit bf5f3f4
Show file tree
Hide file tree
Showing 54 changed files with 785 additions and 268 deletions.
12 changes: 1 addition & 11 deletions .github/release-notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,12 @@
set -eu
set -o pipefail


# Get Release notes for the latest release from CHANGELOG.md
# How to use:
# release-notes.sh CHANGELOG.md

startLine=$(cat $1 | grep -nE "^### " | head -n 1 | cut -d ":" -f 1)
finishLine=$(($(cat $1 | grep -nE "^## " | head -n 2 | tail -n 1 | cut -d ":" -f 1) - 1))
finishLine=$(($(cat $1 | grep -nE "^## \[\d+\." | head -n 2 | tail -n 1 | cut -d ":" -f 1) - 1))
changelog=`sed -n "${startLine},${finishLine}p" $1`;

: "${GITHUB_ACTIONS:=0}"

if [ "$GITHUB_ACTIONS" = "true" ]
then
changelog="${changelog//'%'/'%25'}"
changelog="${changelog//$'\n'/'%0A'}"
changelog="${changelog//$'\r'/'%0D'}"
fi

echo "${changelog}"
74 changes: 27 additions & 47 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,63 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

name: Build and Test

on:
push:
branches:
- '**'
paths-ignore:
- '**.md'
- 'SignNow.Net/SignNow.Net.Examples/**'

tags-ignore:
- '**'
pull_request:
branches:
- 'master'
- 'develop'
paths-ignore:
- '**.md'
tags-ignore:
- '**'

# Workflow
jobs:
build:

name: ${{ matrix.osname }} ${{ matrix.framework }}
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
framework:
- 'net45'
- 'netcoreapp3.1'
- 'net5'

name:
- ubuntu-18.04
- macOS-latest
- windows-latest

include:
- name: ubuntu-18.04
os: ubuntu-18.04
osname: Linux

- name: macOS-latest
os: macOS-latest
osname: macOS

- name: windows-latest
os: windows-latest
osname: Windows

exclude:
- name: ubuntu-18.04
framework: 'net45'

- name: macOS-latest
framework: 'net45'
# Ubuntu
- { name: 'Linux .NET Core 3', os: ubuntu-18.04, framework: 'netcoreapp3.1' }
- { name: 'Linux .NET 5', os: ubuntu-18.04, framework: 'net5' }
# macOs
- { name: 'macOS .NET Core 3', os: macOS-latest, framework: 'netcoreapp3.1' }
- { name: 'macOS .NET 5', os: macOS-latest, framework: 'net5' }
# Windows
- { name: 'Windows .NET Core 3', os: windows-latest, framework: 'netcoreapp3.1' }
- { name: 'Windows .NET 5', os: windows-latest, framework: 'net5' }
- { name: 'Windows .NET 4.5', os: windows-latest, framework: 'net45' }

env:
COREHOST_TRACE: false
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: 1
# prevent the caching of the packages on the build machine
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
# removes logo and telemetry message from first run of dotnet cli
DOTNET_NOLOGO: true
# prevent the download of the XML documentation for the packages
NUGET_XMLDOC_MODE: skip
DOTNET_CLI_TELEMETRY_OPTOUT: 1 # Disable sending usage data to Microsoft
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 # prevent the caching of the packages on the build machine
DOTNET_NOLOGO: true # removes logo and telemetry message from first run of dotnet cli
NUGET_XMLDOC_MODE: skip # prevent the download of the XML documentation for the packages
COVERAGE_PATH: SignNow.Net.Test/bin/Debug

defaults:
run:
shell: pwsh

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Setup .NET SDK Version for Target Framework
shell: pwsh
run: |
If ("${{ matrix.framework }}" -eq "netcoreapp3.1") {
Write-Output "DOTNET_SDK_VERSION=3.1.x" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Expand Down Expand Up @@ -109,21 +94,17 @@ jobs:

- name: Build for .NET Standard 1.2
if: matrix.framework == 'netcoreapp3.1'
shell: pwsh
run: dotnet build SignNow.Net --configuration Debug --framework netstandard1.2

- name: Build for .NET Standard 2.0
if: matrix.framework == 'net5'
shell: pwsh
run: dotnet build SignNow.Net --configuration Debug --framework netstandard2.0

- name: Build for .NET 4.5
if: (runner.os == 'Windows' && matrix.framework == 'net45')
shell: pwsh
run: dotnet build SignNow.Net --configuration Debug --framework net45

- name: Run Tests on ${{ matrix.framework }} with Coverage
shell: pwsh
run: |
dotnet test SignNow.Net.Test `
--configuration Debug --framework ${{ matrix.framework }} `
Expand All @@ -136,7 +117,6 @@ jobs:
path: SignNow.Net.Test/bin/Debug/**/coverage*

- name: Setup Code Coverage report flags
shell: pwsh
run: |
If ("${{ matrix.framework }}" -eq "netcoreapp3.1") {
Write-Output "TARGET_FRAMEWORK=netstandard12" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Expand Down
15 changes: 5 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ jobs:

env:
COREHOST_TRACE: false
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: 1
# prevent the caching of the packages on the build machine
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
# removes logo and telemetry message from first run of dotnet cli
DOTNET_NOLOGO: true
# prevent the download of the XML documentation for the packages
NUGET_XMLDOC_MODE: skip
DOTNET_CLI_TELEMETRY_OPTOUT: 1 # Disable sending usage data to Microsoft
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 # prevent the caching of the packages on the build machine
DOTNET_NOLOGO: true # removes logo and telemetry message from first run of dotnet cli
NUGET_XMLDOC_MODE: skip # prevent the download of the XML documentation for the packages

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -54,7 +50,6 @@ jobs:
id: get-version
run: |
echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
echo ::set-output name=RELEASE_NOTES::$(.github/release-notes.sh CHANGELOG.md)
.github/release-notes.sh CHANGELOG.md > release-notes.txt
- name: Create Release
Expand All @@ -63,7 +58,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
name: SignNow .Net SDK v${{ steps.get-version.outputs.VERSION }}
tag: ${{ steps.get-version.outputs.VERSION }}
body: ${{ steps.get-version.outputs.RELEASE_NOTES }}
bodyFile: ${{ github.workspace }}/release-notes.txt
allowUpdates: true
artifacts: ${{ github.workspace }}/SignNow.Net/bin/Publish/*.nupkg
artifactContentType: application/octet-stream
Expand Down
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com)
and this project adheres to [Semantic Versioning](http://semver.org).

## [develop] - TBD
- `IDocumentService.PrefillTextFieldsAsync` that allows to prefill document fields
## [Unreleased] - TBD

## [1.0.0] - 2022-02-26
### Added
- `IDocumentService.PrefillTextFieldsAsync` that allows you to prefill document fields
- `IDocumentService.EditDocumentAsync` that allows you to add/change various fields
- `IFieldEditable` that represents editable Field attributes
- `Model.EditFields.TextField` that allows you to configure text field and add/change the document fields

### Changed
- `FieldJsonAttributes` added to `ISignNowFields` that allows you to get Field attributes

## [0.9.0] - 2021-07-07
### Added
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ Get your account at <https://www.signnow.com/developers>
- [Create a one-time link to download the document as a PDF](#share-document-via-link)
- [Get the history of a document](#document-history)
- [Check the status of the document][check_sign_status example]
- [Move document into specified folder][move_document example]
- [Move document into specified folder][move_document example]
- [Edit document][edit_document example]
- [Prefill document text fields][prefill_text_field example]
- [Template](#template)
- [Create a template by flattening an existing document](#create-template)
- [Create document from the template][create_document example]
Expand Down Expand Up @@ -580,7 +582,7 @@ For XML documentation generation, install InheritDocTool:
dotnet tool install -g InheritDocTool
```

More about the InheritDoc [here](https://www.inheritdoc.io)
More about the InheritDoc [here](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/examples#document-a-hierarchy-of-classes-and-interfaces)

### <a name="important-notes"></a>Important notes

Expand Down Expand Up @@ -611,7 +613,6 @@ If you have questions about the SignNow API, please visit [SignNow API Reference
[actions build link]: https://github.com/signnow/SignNow.NET/actions?query=workflow%3A%22Build+and+Test%22
[codecov badge]: https://codecov.io/gh/signnow/SignNow.NET/branch/develop/graph/badge.svg "Code coverage report"
[codecov link]: https://codecov.io/gh/signnow/SignNow.NET
[codacy badge]: https://api.codacy.com/project/badge/Grade/1aea9e4b60eb4b6a8c458e16fc8bdb24 "Codacy Repository certification"
[nuget badge]: https://img.shields.io/nuget/v/SignNow.Net.svg?style=flat-square "NuGet package latest SDK version"
[nuget link]: https://www.nuget.org/packages/SignNow.Net
[nuget downloads badge]: https://img.shields.io/nuget/dt/SignNow.Net.svg?style=flat-square
Expand Down Expand Up @@ -651,6 +652,8 @@ If you have questions about the SignNow API, please visit [SignNow API Reference
[create_one_time_link example]: https://github.com/signnow/SignNow.NET/blob/develop/SignNow.Net.Examples/Documents/CreateOneTimeLinkToDownloadTheDocument.cs
[document_history example]: https://github.com/signnow/SignNow.NET/blob/develop/SignNow.Net.Examples/Documents/GetTheDocumentHistory.cs
[move_document example]: https://github.com/signnow/SignNow.NET/blob/develop/SignNow.Net.Examples/Documents/MoveTheDocumentToFolder.cs
[edit_document example]: https://github.com/signnow/SignNow.NET/blob/develop/SignNow.Net.Examples/Documents/EditDocumentTextFields.cs
[prefill_text_field example]: https://github.com/signnow/SignNow.NET/blob/develop/SignNow.Net.Examples/Documents/PrefillTextFields.cs

<!-- Templates -->
[create_template example]: https://github.com/signnow/SignNow.NET/blob/develop/SignNow.Net.Examples/Documents/CreateTemplateFromTheDocument.cs
Expand Down
30 changes: 30 additions & 0 deletions SignNow.Net.Examples/Documents/EditDocumentTextFields.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using SignNow.Net.Interfaces;
using SignNow.Net.Model;
using SignNow.Net.Model.EditFields;
using SignNow.Net.Model.Responses;

namespace SignNow.Net.Examples.Documents
{
// public class EditDocumentTextFields
public static partial class DocumentExamples
{
/// <summary>
/// Updates a document by adding/overwriting fields or elements (texts, checks, signatures, hyperlinks, attachments)
/// </summary>
/// <param name="documentId">Identity of the document to add/edit fields for.</param>
/// <param name="fields">Collection of the <see cref="IFieldEditable">fields</see></param>
/// <param name="token">Access token</param>
/// <returns></returns>
public static async Task<EditDocumentResponse> EditDocumentTextFields(string documentId, IEnumerable<IFieldEditable> fields, Token token)
{
// using token from the Authorization step
var signNowContext = new SignNowContext(token);

return await signNowContext.Documents
.EditDocumentAsync(documentId, fields)
.ConfigureAwait(false);
}
}
}
5 changes: 3 additions & 2 deletions SignNow.Net.Examples/Documents/PrefillTextFields.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using SignNow.Net.Model;
using SignNow.Net.Model.EditFields;

namespace SignNow.Net.Examples.Documents
{
Expand All @@ -11,10 +12,10 @@ public static partial class DocumentExamples
/// Works only with Text field types.
/// </summary>
/// <param name="documentId">Identity of the document to prefill values for.</param>
/// <param name="fields">Collection of the <see cref="PrefillTextField">fields</see></param>
/// <param name="fields">Collection of the <see cref="TextField">fields</see></param>
/// <param name="token">Access token</param>
/// <returns></returns>
public static async Task PrefillTextFields(string documentId, IEnumerable<PrefillTextField> fields, Token token)
public static async Task PrefillTextFields(string documentId, IEnumerable<TextField> fields, Token token)
{
// using token from the Authorization step
var signNowContext = new SignNowContext(token);
Expand Down
59 changes: 57 additions & 2 deletions SignNow.Net.Examples/ExamplesRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
using SignNow.Net.Examples.Folders;
using SignNow.Net.Examples.Invites;
using SignNow.Net.Examples.Users;
using SignNow.Net.Interfaces;
using SignNow.Net.Model;
using SignNow.Net.Model.EditFields;
using SignNow.Net.Model.Requests;
using SignNow.Net.Model.Requests.GetFolderQuery;
using SignNow.Net.Test.Context;
Expand Down Expand Up @@ -272,7 +274,6 @@ public async Task CreateOneTimeLinkToDownloadTheDocumentTest()
StringAssert.Contains(oneTimeLink.Url.Host, "signnow.com");
}


/// <summary>
/// Run test for example: <see cref="DocumentExamples.MoveTheDocumentToFolder"/>
/// </summary>
Expand Down Expand Up @@ -309,6 +310,60 @@ await DocumentExamples
await testContext.Folders.DeleteFolderAsync(folderToMoveUpdated.Id).ConfigureAwait(false);
}

/// <summary>
/// Run test for example: <see cref="DocumentExamples.EditDocumentTextFields"/>
/// Run test for example: <see cref="DocumentExamples.PrefillTextFields"/>
/// </summary>
[TestMethod]
public async Task PrefillTextFieldsTest()
{
// Upload test document
await using var fileStream = File.OpenRead(PdfWithSignatureField);
var testDocument = await testContext.Documents
.UploadDocumentWithFieldExtractAsync(fileStream, "PrefillDocumentTest.pdf")
.ConfigureAwait(false);

var documentUploaded = await testContext.Documents.GetDocumentAsync(testDocument.Id).ConfigureAwait(false);
Assert.IsNull(documentUploaded.Fields.FirstOrDefault()?.JsonAttributes.PrefilledText);

// Add simple text field which will be prefilled next.
var editFields = new List<IFieldEditable>
{
new TextField
{
PageNumber = 0,
Name = "Text_1",
Height = 40,
Width = 200,
X = 10,
Y = 40,
Role = "Signer 1"
}
};

var editDocument = await DocumentExamples
.EditDocumentTextFields(testDocument.Id, editFields, token)
.ConfigureAwait(false);

var documentEdited = await testContext.Documents.GetDocumentAsync(editDocument.Id).ConfigureAwait(false);
Assert.IsNull(documentEdited.Fields.FirstOrDefault()?.JsonAttributes.PrefilledText);
Assert.AreEqual("Text_1", documentEdited.Fields.FirstOrDefault()?.JsonAttributes.Name);

var fields = new List<TextField>
{
new TextField
{
Name = "Text_1",
PrefilledText = "Test Prefill"
}
};

await DocumentExamples.PrefillTextFields(testDocument.Id, fields, token).ConfigureAwait(false);

var documentFinal = await testContext.Documents.GetDocumentAsync(testDocument.Id).ConfigureAwait(false);
Assert.AreEqual("Test Prefill", documentFinal.Fields.FirstOrDefault()?.JsonAttributes.PrefilledText);
}

#endregion

#region Invites Examples
Expand Down Expand Up @@ -500,7 +555,7 @@ public async Task CreateTemplateFromDocumentTest()
.UploadDocumentWithFieldExtract(PdfWithSignatureField, token).ConfigureAwait(false);
disposableDocumentId = document?.Id;

var templateName = "Template Name";
const string templateName = "Template Name";
var result = await DocumentExamples.CreateTemplateFromTheDocument(document?.Id, templateName, token).ConfigureAwait(false);
var template = await testContext.Documents.GetDocumentAsync(result.Id).ConfigureAwait(false);

Expand Down
1 change: 0 additions & 1 deletion SignNow.Net.Test/AcceptanceTests/DocumentServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down
Loading

0 comments on commit bf5f3f4

Please sign in to comment.