diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..96f887a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,20 @@ +.DS_Store +.dockerignore +.editorconfig +.eslintrc.json +.gitattributes +.gitignore +.prettierignore +.pre-commit-config.yaml +/.git +/.github +/.idea +/build +/node_modules +/pages +Dockerfile +Makefile +README.md +docker-compose.yml +package-lock.json +package.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9aa7052 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +[*.js] +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true + +[Makefile] +indent_style = tab + +[package.json] +indent_style = space +indent_size = 2 diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..cc7e9e6 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,274 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 12 + }, + "rules": { + "accessor-pairs": "error", + "array-bracket-newline": "error", + "array-bracket-spacing": "off", + "array-callback-return": "off", + "array-element-newline": "off", + "arrow-body-style": "error", + "arrow-parens": "off", + "arrow-spacing": [ + "error", + { + "after": true, + "before": true + } + ], + "block-scoped-var": "off", + "block-spacing": "off", + "brace-style": "off", + "camelcase": "off", + "capitalized-comments": "off", + "class-methods-use-this": "error", + "comma-dangle": "off", + "comma-spacing": "off", + "comma-style": [ + "error", + "last" + ], + "complexity": "off", + "computed-property-spacing": [ + "error", + "never" + ], + "consistent-return": "off", + "consistent-this": "off", + "curly": "off", + "default-case": "error", + "default-case-last": "off", + "default-param-last": "error", + "dot-location": [ + "error", + "property" + ], + "dot-notation": "off", + "eol-last": "off", + "eqeqeq": "off", + "func-call-spacing": "error", + "func-name-matching": "error", + "func-names": "off", + "func-style": "off", + "function-call-argument-newline": [ + "error", + "consistent" + ], + "function-paren-newline": "off", + "generator-star-spacing": "error", + "grouped-accessor-pairs": "error", + "guard-for-in": "off", + "id-denylist": "error", + "id-length": "off", + "id-match": "error", + "implicit-arrow-linebreak": "off", + "indent": "off", + "init-declarations": "off", + "jsx-quotes": "error", + "key-spacing": "off", + "keyword-spacing": "off", + "line-comment-position": "off", + "linebreak-style": "off", + "lines-around-comment": "off", + "lines-between-class-members": "error", + "max-classes-per-file": "error", + "max-depth": "off", + "max-len": "off", + "max-lines": "off", + "max-lines-per-function": "off", + "max-nested-callbacks": "error", + "max-params": "off", + "max-statements": "off", + "max-statements-per-line": "off", + "multiline-comment-style": "off", + "multiline-ternary": [ + "error", + "always-multiline" + ], + "new-parens": "off", + "newline-per-chained-call": "off", + "no-alert": "error", + "no-array-constructor": "error", + "no-await-in-loop": "error", + "no-bitwise": "off", + "no-caller": "error", + "no-confusing-arrow": "off", + "no-console": "off", + "no-constructor-return": "error", + "no-continue": "off", + "no-div-regex": "error", + "no-duplicate-imports": "error", + "no-else-return": "off", + "no-empty": [ + "error", + { + "allowEmptyCatch": true + } + ], + "no-empty-function": "off", + "no-eq-null": "off", + "no-eval": "error", + "no-extend-native": "error", + "no-extra-bind": "error", + "no-extra-label": "error", + "no-extra-parens": "off", + "no-floating-decimal": "off", + "no-implicit-globals": "off", + "no-implied-eval": "error", + "no-inline-comments": "off", + "no-inner-declarations": [ + "error", + "functions" + ], + "no-invalid-this": "off", + "no-iterator": "error", + "no-label-var": "error", + "no-labels": "error", + "no-lone-blocks": "error", + "no-lonely-if": "error", + "no-loop-func": "off", + "no-loss-of-precision": "error", + "no-magic-numbers": "off", + "no-mixed-operators": "off", + "no-multi-assign": "off", + "no-multi-spaces": "off", + "no-multi-str": "error", + "no-multiple-empty-lines": "error", + "no-negated-condition": "off", + "no-nested-ternary": "off", + "no-new": "off", + "no-new-func": "error", + "no-new-object": "error", + "no-new-wrappers": "error", + "no-nonoctal-decimal-escape": "error", + "no-octal-escape": "error", + "no-param-reassign": "off", + "no-plusplus": "off", + "no-promise-executor-return": "error", + "no-proto": "error", + "no-restricted-exports": "error", + "no-restricted-globals": "error", + "no-restricted-imports": "error", + "no-restricted-properties": "error", + "no-restricted-syntax": "error", + "no-return-assign": "off", + "no-return-await": "error", + "no-script-url": "error", + "no-self-assign": [ + "error", + { + "props": false + } + ], + "no-self-compare": "off", + "no-sequences": "off", + "no-shadow": "off", + "no-tabs": "off", + "no-template-curly-in-string": "error", + "no-ternary": "off", + "no-throw-literal": "error", + "no-trailing-spaces": "off", + "no-undef-init": "error", + "no-undefined": "error", + "no-underscore-dangle": "off", + "no-unmodified-loop-condition": "error", + "no-unneeded-ternary": "error", + "no-unreachable-loop": "off", + "no-unsafe-optional-chaining": "error", + "no-unused-expressions": "off", + "no-use-before-define": "off", + "no-useless-backreference": "error", + "no-useless-call": "off", + "no-useless-computed-key": "error", + "no-useless-concat": "error", + "no-useless-constructor": "error", + "no-useless-rename": "error", + "no-useless-return": "error", + "no-var": "off", + "no-void": "off", + "no-warning-comments": "error", + "no-whitespace-before-property": "error", + "nonblock-statement-body-position": [ + "error", + "any" + ], + "object-curly-newline": "off", + "object-curly-spacing": "off", + "object-shorthand": "off", + "one-var": "off", + "one-var-declaration-per-line": "off", + "operator-assignment": [ + "error", + "always" + ], + "operator-linebreak": "off", + "padded-blocks": "off", + "padding-line-between-statements": "error", + "prefer-arrow-callback": "off", + "prefer-const": "off", + "prefer-destructuring": "off", + "prefer-exponentiation-operator": "off", + "prefer-named-capture-group": "off", + "prefer-numeric-literals": "error", + "prefer-object-spread": "error", + "prefer-promise-reject-errors": "error", + "prefer-regex-literals": "error", + "prefer-rest-params": "off", + "prefer-spread": "off", + "prefer-template": "off", + "quote-props": "off", + "quotes": "off", + "radix": "off", + "require-atomic-updates": "error", + "require-await": "error", + "require-unicode-regexp": "off", + "rest-spread-spacing": [ + "error", + "never" + ], + "semi": "off", + "semi-spacing": "off", + "semi-style": [ + "error", + "last" + ], + "sort-imports": "error", + "sort-keys": "off", + "sort-vars": "off", + "space-before-blocks": "off", + "space-before-function-paren": "off", + "space-in-parens": "off", + "space-infix-ops": "off", + "space-unary-ops": "off", + "spaced-comment": "off", + "strict": "off", + "switch-colon-spacing": [ + "error", + { + "after": false, + "before": false + } + ], + "symbol-description": "error", + "template-curly-spacing": [ + "error", + "never" + ], + "template-tag-spacing": "error", + "unicode-bom": [ + "error", + "never" + ], + "vars-on-top": "off", + "wrap-iife": "off", + "wrap-regex": "off", + "yield-star-spacing": "error", + "yoda": "off" + } +} diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4130d26 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,15 @@ +.dockerignore export-ignore +.editorconfig export-ignore +.eslintrc.json export-ignore +.gitattributes export-ignore +.gitignore export-ignore +/.github export-ignore +/build export-ignore +/node_modules export-ignore +/pages export-ignore +Dockerfile export-ignore +Makefile export-ignore +README.md export-ignore +docker-compose.yml export-ignore +package-lock.json export-ignore +package.json export-ignore diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml new file mode 100644 index 0000000..9749588 --- /dev/null +++ b/.github/workflows/pull-requests.yml @@ -0,0 +1,27 @@ +name: Lint and Prettier Check + +on: + pull_request: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-22.04 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '16' + + - name: Install dependencies + run: npm install + + - name: Run ESLint + run: npm run lint + + - name: Run Prettier check + run: npm run prettier diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..f568f4e --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,36 @@ +name: Deploy to Pages + +on: + push: + branches: ["main"] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Build + run: make build && make pages + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: 'pages' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f26db73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea +build/ +node_modules/ +pages/ diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..2ae2ec9 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +*.html +*.min.js +/build +/pages +build diff --git a/404.html b/404.html new file mode 100644 index 0000000..c01c979 --- /dev/null +++ b/404.html @@ -0,0 +1,12 @@ + + + + Page not found - BMLT + + + + + +

404: Page not found - BMLT

+ + \ No newline at end of file diff --git a/CNAME b/CNAME new file mode 100644 index 0000000..3cce1b0 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +converter.bmlt.app diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d5f85dc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM busybox:1.36 + +RUN adduser -D website +WORKDIR /home/website +COPY . . +USER website +CMD ["busybox", "httpd", "-f", "-v", "-p", "8000"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4ab1832 --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +COMMIT := $(shell git rev-parse --short=8 HEAD) +ZIP_FILENAME := "bmlt-data-converter.zip" +BUILD_DIR := "build" + +help: ## Print the help documentation + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: build +build: ## Build + git archive --format=zip --output=${ZIP_FILENAME} $(COMMIT) + mkdir -p ${BUILD_DIR} && mv ${ZIP_FILENAME} ${BUILD_DIR} + +.PHONY: pages +pages: ## Preps GitHub Pages Deploy + mkdir -p pages && unzip ${BUILD_DIR}/${ZIP_FILENAME} -d pages + +.PHONY: clean +clean: ## clean + rm -rf ${BUILD_DIR} + +.PHONY: image-build +image-build: ## Builds Docker Image + docker build -t bmlt-data-converter:latest . + +.PHONY: image-serve +image-serve: image-build ## Runs Docker Image + docker run -it --rm --init -p 8000:8000 bmlt-data-converter:latest + +.PHONY: image-exec +image-exec: image-build ## Runs Docker Exec + docker run -it bmlt-data-converter:latest /bin/sh + +.PHONY: serve +serve: ## serve + python3 -m http.server 8000 + +.PHONY: lint +lint: ## JS Lint + npm run lint + npm run prettier + +.PHONY: lint-fix +lint-fix: ## JS Lint Fix + npm run lint:fix + npm run prettier:fix diff --git a/README.md b/README.md new file mode 100644 index 0000000..55738a5 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# BMLT Data Converter + +* Converts BMLT meeting data from a JSON endpoint to CSV diff --git a/assets/css/main.css b/assets/css/main.css new file mode 100644 index 0000000..24ec14c --- /dev/null +++ b/assets/css/main.css @@ -0,0 +1,57 @@ +body { + font-family: Arial, sans-serif; +} + +h1 { + text-align: center; +} + +#export-form { + max-width: 600px; + margin: 0 auto; + padding: 20px; + background-color: #f7f7f7; + border: 1px solid #ccc; + border-radius: 5px; + box-sizing: border-box; +} + +label { + display: block; + margin-bottom: 10px; + font-weight: bold; +} + +input[type="text"] { + width: 100%; + padding: 10px; + margin-bottom: 10px; + border: 1px solid #ccc; + border-radius: 3px; + box-sizing: border-box; +} + +button { + background-color: #007bff; + color: #fff; + border: none; + padding: 10px 20px; + border-radius: 3px; + cursor: pointer; +} + +button:hover { + background-color: #0056b3; +} + +a { + display: block; + margin-top: 10px; + text-align: center; + text-decoration: none; + color: #007bff; +} + +a:hover { + text-decoration: underline; +} diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..082a715 --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,49 @@ +function fetchMeetings(query, callback) { + const script = document.createElement('script'); + script.src = query + '&callback=' + callback.name; + document.body.appendChild(script); +} + +function handleMeetingsData(meetings) { + const csvContent = 'data:text/csv;charset=utf-8,' + encodeURIComponent( + convertToCSV(meetings) + ); + const downloadLink = document.getElementById('downloadLink'); + downloadLink.href = csvContent; + downloadLink.style.display = 'block'; +} + +function convertToCSV(data) { + const csvRows = []; + const keys = Object.keys(data[0]); + + // header row + csvRows.push(keys.join(',')); + + data.forEach((row) => { + const values = keys.map((key) => { + let value = row[key]; + if (typeof value === 'string') { + // Escape double quotes and wrap in double quotes if it contains a comma + if (value.includes(',') || value.includes('"')) { + value = `"${value.replace(/"/g, '""')}"`; + } + } + return value; + }); + + csvRows.push(values.join(',')); + }); + + return csvRows.join('\n'); +} + +function exportToCSV() { + const query = document.getElementById('query').value; + if (!query.includes('/client_interface/jsonp')) { + alert('Invalid BMLT query URL, must use jsonp endpoint.'); + return; + } + + fetchMeetings(query, handleMeetingsData); +} diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..6f09b27 Binary files /dev/null and b/favicon.ico differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..24fcfd5 --- /dev/null +++ b/index.html @@ -0,0 +1,21 @@ + + + + BMLT CSV Export + + + + + +

BMLT CSV Export

+
+ + +
+ + +
+ + + + \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..aa7a084 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "bmlt-data-converter", + "scripts": { + "lint": "npx eslint assets/js/main.js", + "lint:fix": "npm run lint assets/js/main.js --fix", + "prettier": "npx prettier assets/js --check", + "prettier:fix": "npm run prettier assets/js --write" + }, + "author": "pjaudiomv", + "license": "MIT", + "devDependencies": { + "eslint": "^7.32.0", + "prettier": "2.8.8" + } +}