Skip to content

Commit c2d627f

Browse files
authored
Merge pull request #1 from itk-dev/os2forms_sync
Added os2forms_sync module
2 parents 579ebff + 1b017df commit c2d627f

33 files changed

Lines changed: 2214 additions & 1 deletion

.github/workflows/pr.yaml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
on: pull_request
2+
name: PR Review
3+
jobs:
4+
changelog:
5+
runs-on: ubuntu-latest
6+
name: Changelog should be updated
7+
strategy:
8+
fail-fast: false
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
with:
13+
fetch-depth: 2
14+
15+
- name: Git fetch
16+
run: git fetch
17+
18+
- name: Check that changelog has been updated.
19+
run: git diff --exit-code origin/${{ github.base_ref }} -- CHANGELOG.md && exit 1 || exit 0
20+
21+
test-composer-files:
22+
name: Validate composer
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
php-versions: [ '7.4', '8.0', '8.1' ]
27+
dependency-version: [ prefer-lowest, prefer-stable ]
28+
steps:
29+
- uses: actions/checkout@master
30+
- name: Setup PHP, with composer and extensions
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php-versions }}
34+
extensions: json
35+
coverage: none
36+
tools: composer:v2
37+
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
38+
- name: Get composer cache directory
39+
id: composer-cache
40+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
41+
- name: Cache dependencies
42+
uses: actions/cache@v2
43+
with:
44+
path: ${{ steps.composer-cache.outputs.dir }}
45+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
46+
restore-keys: ${{ runner.os }}-composer-
47+
- name: Validate composer files
48+
run: |
49+
composer validate --strict composer.json
50+
# Check that dependencies resolve.
51+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
52+
53+
php-coding-standards:
54+
name: PHP coding standards
55+
runs-on: ubuntu-latest
56+
strategy:
57+
matrix:
58+
php-versions: [ '7.4', '8.0', '8.1' ]
59+
dependency-version: [ prefer-lowest, prefer-stable ]
60+
steps:
61+
- uses: actions/checkout@master
62+
- name: Setup PHP, with composer and extensions
63+
uses: shivammathur/setup-php@v2
64+
with:
65+
php-version: ${{ matrix.php-versions }}
66+
extensions: json
67+
coverage: none
68+
tools: composer:v2
69+
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
70+
- name: Get composer cache directory
71+
id: composer-cache
72+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
73+
- name: Cache dependencies
74+
uses: actions/cache@v2
75+
with:
76+
path: ${{ steps.composer-cache.outputs.dir }}
77+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
78+
restore-keys: ${{ runner.os }}-composer-
79+
- name: Install Dependencies
80+
run: |
81+
composer install --no-interaction --no-progress
82+
- name: PHPCS
83+
run: |
84+
composer coding-standards-check/phpcs
85+
86+
php-code-analysis:
87+
name: PHP code analysis
88+
runs-on: ubuntu-latest
89+
strategy:
90+
matrix:
91+
php-versions: [ '7.4', '8.0', '8.1' ]
92+
dependency-version: [ prefer-lowest, prefer-stable ]
93+
steps:
94+
- uses: actions/checkout@master
95+
- name: Setup PHP, with composer and extensions
96+
uses: shivammathur/setup-php@v2
97+
with:
98+
php-version: ${{ matrix.php-versions }}
99+
extensions: json, gd
100+
coverage: none
101+
tools: composer:v2
102+
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
103+
- name: Get composer cache directory
104+
id: composer-cache
105+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
106+
- name: Cache dependencies
107+
uses: actions/cache@v2
108+
with:
109+
path: ${{ steps.composer-cache.outputs.dir }}
110+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
111+
restore-keys: ${{ runner.os }}-composer-
112+
- name: drupal-check
113+
run: |
114+
# We need a Drupal project to run drupal-check (cf. https://github.com/mglaman/drupal-check#usage)
115+
# Install Drupal
116+
composer --no-interaction create-project drupal/recommended-project:^9 --stability=dev drupal
117+
# Copy our module source code into the Drupal module folder.
118+
mkdir -p drupal/web/modules/contrib/os2forms_sync
119+
cp -r os2forms_sync.* composer.json src drupal/web/modules/contrib/os2forms_sync
120+
# Add our module as a composer repository.
121+
composer --no-interaction --working-dir=drupal config repositories.os2forms/os2forms_sync path web/modules/contrib/os2forms_sync
122+
# Restore Drupal composer repository.
123+
composer --no-interaction --working-dir=drupal config repositories.drupal composer https://packages.drupal.org/8
124+
125+
# Require our module.
126+
composer --no-interaction --working-dir=drupal require 'os2forms/os2forms_sync:*'
127+
128+
# Check code
129+
composer --no-interaction --working-dir=drupal require --dev drupal/core-dev
130+
cd drupal/web/modules/contrib/os2forms_sync
131+
# Remove our non-dev dependencies to prevent duplicated Drupal installation
132+
# PHP Fatal error: Cannot redeclare drupal_get_filename() (previously declared in /home/runner/work/os2forms_sync/os2forms_sync/drupal/web/modules/contrib/os2forms_sync/vendor/drupal/core/includes/bootstrap.inc:190) in /home/runner/work/os2forms_sync/os2forms_sync/drupal/web/core/includes/bootstrap.inc on line 190
133+
# Use sed to remove the "require" property in composer.json
134+
sed -i '/^\s*"require":/,/^\s*}/d' composer.json
135+
composer --no-interaction install
136+
composer code-analysis
137+
138+
markdown-coding-standards:
139+
runs-on: ubuntu-20.04
140+
name: Markdown coding standards
141+
steps:
142+
- name: Checkout
143+
uses: actions/checkout@v2
144+
- name: Get yarn cache directory path
145+
id: yarn-cache-dir-path
146+
run: echo "::set-output name=dir::$(yarn cache dir)"
147+
- name: Cache yarn packages
148+
uses: actions/cache@v2
149+
id: yarn-cache
150+
with:
151+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
152+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
153+
restore-keys: |
154+
${{ runner.os }}-yarn-
155+
- name: Yarn install
156+
uses: actions/setup-node@v2
157+
with:
158+
node-version: '16'
159+
- run: yarn install
160+
- name: coding-standards-check
161+
run: yarn coding-standards-check

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vendor
2+
composer.lock
3+
node_modules
4+
yarn.lock

.markdownlintrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// @see https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
3+
// MD013/line-length - Line length
4+
"MD013": {
5+
// Exclude code blocks
6+
"code_blocks": false
7+
},
8+
"MD024": {
9+
"siblings_only": true
10+
}
11+
}
12+
13+
// Local Variables:
14+
// mode: json
15+
// End:

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- markdownlint-disable MD024 -->
2+
# Changelog
3+
4+
All notable changes to this project will be documented in this file.
5+
6+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7+
and this project adheres to [Semantic
8+
Versioning](https://semver.org/spec/v2.0.0.html).
9+
10+
## [Unreleased]
11+
12+
### Added
13+
14+
- Added OS2Forms sync module
15+
16+
[Unreleased]: https://github.com/itk-dev/os2forms_sync/compare/main...HEAD

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 ITK Development
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,47 @@
1-
# os2forms_sync
1+
# OS2Forms sync
2+
3+
## Installation
4+
5+
```sh
6+
composer require os2forms/os2forms_sync
7+
drush pm:enable os2forms_sync
8+
```
9+
10+
Edit settings on `/admin/os2forms_sync/settings`.
11+
12+
## API
13+
14+
See [API](docs/API.md) for details on the API.
15+
16+
## Usage
17+
18+
Publish a webform by checking “Publish” under webform setting » Third party
19+
settings » OS2Forms » OS2Forms sync
20+
21+
All published webforms are listed on `/admin/os2forms/sync/webform` (API data on
22+
`/os2forms/sync/jsonapi/webform`).
23+
24+
Webforms available for import are listed on `/admin/os2forms/sync/webform`.
25+
26+
## Drush commands
27+
28+
```sh
29+
drush os2forms-sync:import --help
30+
```
31+
32+
## Coding standards
33+
34+
```sh
35+
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php7.4-fpm:latest composer install
36+
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php7.4-fpm:latest composer coding-standards-check
37+
38+
docker run --rm --interactive --tty --volume ${PWD}:/app node:18 yarn --cwd /app install
39+
docker run --rm --interactive --tty --volume ${PWD}:/app node:18 yarn --cwd /app coding-standards-check
40+
```
41+
42+
## Code analysis
43+
44+
```sh
45+
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php7.4-fpm:latest composer install
46+
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php7.4-fpm:latest composer code-analysis
47+
```

assets/css/webform-index.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.os2forms-sync-webform-index [type="search"] {
2+
width: 100%;
3+
}
4+
5+
.os2forms-sync-webform-index .filters ul,
6+
.os2forms-sync-webform-index .filters li {
7+
margin-left: 0;
8+
}
9+
10+
.os2forms-sync-webform-index .filters li {
11+
display: inline-block;
12+
padding-right: 1em;
13+
}
14+
15+
.os2forms-sync-webform-index .metadata {
16+
display: flex;
17+
justify-content: space-between;
18+
}
19+
20+
.os2forms-sync-webform-index .settings {
21+
margin-top: 2em;
22+
}

assets/js/webform-index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
const webforms = document.querySelectorAll('.os2forms-sync-webform-index .os2forms-sync-webform')
3+
const searchInput = document.querySelector('.os2forms-sync-webform-index [type="search"]')
4+
5+
if (!(webforms && searchInput)) {
6+
return
7+
}
8+
9+
/**
10+
* Combine values of all `data-indexed` attributes on descendants.
11+
*/
12+
const index = (el) => {
13+
return [...el.querySelectorAll('[data-indexed]')]
14+
.map(e => e.dataset.indexed)
15+
.join(' ')
16+
}
17+
18+
const liveSearch = () => {
19+
const query = searchInput.value.toLowerCase()
20+
webforms.forEach(webform => {
21+
if (!webform.indexed) {
22+
webform.indexed = [...webform.querySelectorAll('[data-indexed]')]
23+
.map(e => e.dataset.indexed)
24+
.join(' ')
25+
.toLowerCase()
26+
}
27+
webform.hidden = !webform.indexed.includes(query)
28+
})
29+
}
30+
31+
let typingTimer
32+
const typingDelay = 250
33+
34+
searchInput.addEventListener('keyup', () => {
35+
clearTimeout(typingTimer)
36+
typingTimer = setTimeout(liveSearch, typingDelay)
37+
})
38+
})

composer.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "os2forms/os2forms_sync",
3+
"description": "OS2Forms sync",
4+
"type": "drupal-module",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Mikkel Ricky",
9+
"email": "rimi@aarhus.dk"
10+
}
11+
],
12+
"minimum-stability": "dev",
13+
"prefer-stable": true,
14+
"repositories": [
15+
{
16+
"type": "composer",
17+
"url": "https://packages.drupal.org/8"
18+
}
19+
],
20+
"require": {
21+
"drupal/webform": "^6",
22+
"drush/drush": "^10 || ^11",
23+
"symfony/options-resolver": "^5.4 || ^6.0"
24+
},
25+
"require-dev": {
26+
"drupal/coder": "^8.3",
27+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
28+
"mglaman/drupal-check": "^1.4",
29+
"phpunit/phpunit": "^9.5"
30+
},
31+
"autoload-dev": {
32+
"//": "Make sure that our PHPUnit test classes can load our Drupal module classes",
33+
"psr-4": { "Drupal\\os2forms_sync\\": "src/" }
34+
},
35+
"scripts": {
36+
"code-analysis/drupal-check": [
37+
"drupal-check --deprecations --analysis --exclude-dir=vendor *.* src"
38+
],
39+
"code-analysis": [
40+
"@code-analysis/drupal-check"
41+
],
42+
"coding-standards-check/phpcs": [
43+
"phpcs --standard=phpcs.xml.dist"
44+
],
45+
"coding-standards-check": [
46+
"@coding-standards-check/phpcs"
47+
],
48+
"coding-standards-apply/phpcbf": [
49+
"phpcbf --standard=phpcs.xml.dist"
50+
],
51+
"coding-standards-apply": [
52+
"@coding-standards-apply/phpcbf"
53+
],
54+
"test": [
55+
"phpunit tests"
56+
]
57+
},
58+
"config": {
59+
"allow-plugins": {
60+
"dealerdirect/phpcodesniffer-composer-installer": true
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)