Compare commits
16 Commits
main
..
2c359e7d7a
| Author | SHA1 | Date | |
|---|---|---|---|
|
2c359e7d7a
|
|||
|
bfcabfd182
|
|||
|
d9cee2be40
|
|||
|
0cb22f7dcd
|
|||
|
00ead3f73d
|
|||
|
29b5f84d92
|
|||
|
56bddfb04a
|
|||
|
f5758f8aa9
|
|||
|
4751ea5ff9
|
|||
|
3c098b7145
|
|||
|
2bc1ada93d
|
|||
|
4e47af6f5e
|
|||
|
807924dd8d
|
|||
|
cd9c4a3553
|
|||
|
681ec76fd5
|
|||
|
d0693b71ec
|
@@ -1,8 +0,0 @@
|
|||||||
.git
|
|
||||||
.github
|
|
||||||
.env
|
|
||||||
target/
|
|
||||||
tests/
|
|
||||||
Dockerfile
|
|
||||||
web/dist
|
|
||||||
api/config/local.*
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
name: 'cargo tarpaulin'
|
||||||
|
description: 'Gather Rust code coverage information with Tarpaulin'
|
||||||
|
inputs:
|
||||||
|
version:
|
||||||
|
description: 'The version of cargo-tarpaulin to install'
|
||||||
|
required: true
|
||||||
|
default: '0.19.0'
|
||||||
|
|
||||||
|
args:
|
||||||
|
required: false
|
||||||
|
description: 'Extra command line arguments passed to cargo-tarpaulin'
|
||||||
|
|
||||||
|
out-type:
|
||||||
|
description: 'Output format of coverage report [possible values: Json, Toml, Stdout, Xml, Html, Lcov]'
|
||||||
|
required: false
|
||||||
|
default: 'Xml'
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: 'composite'
|
||||||
|
steps:
|
||||||
|
- run: ${{ github.action_path }}/cargo-tarpaulin.sh ${{ inputs.out-type }} ${{ inputs.version }} ${{ inputs.args }}
|
||||||
|
shell: bash
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
sudo apt-get update -y
|
||||||
|
sudo apt-get install -y --no-install-recommends openssl taskwarrior
|
||||||
|
|
||||||
|
out_type="$1"
|
||||||
|
version="$2"
|
||||||
|
args="$3"
|
||||||
|
tar_file="cargo-tarpaulin-${version}-travis.tar.gz"
|
||||||
|
|
||||||
|
wget "https://github.com/xd009642/tarpaulin/releases/download/${version}/${tar_file}"
|
||||||
|
tar zxvf "$tar_file"
|
||||||
|
chmod +x cargo-tarpaulin
|
||||||
|
|
||||||
|
exec env RUST_LOG=debug ./cargo-tarpaulin tarpaulin --ignore-tests -o "$out_type" $args
|
||||||
@@ -10,15 +10,7 @@ jobs:
|
|||||||
security_audit:
|
security_audit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- uses: actions/checkout@v1
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Install Rust
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
- uses: Swatinem/rust-cache@v1
|
|
||||||
- uses: actions-rs/audit-check@v1
|
- uses: actions-rs/audit-check@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
+35
-104
@@ -1,126 +1,57 @@
|
|||||||
|
on: [push]
|
||||||
|
|
||||||
name: CI
|
name: CI
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
format:
|
||||||
rustfmt:
|
name: rustfmt
|
||||||
name: Rustfmt
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- uses: actions/checkout@v2
|
||||||
uses: actions/checkout@v3
|
- uses: actions-rs/toolchain@v1
|
||||||
- name: Install Rust toolchain
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
with:
|
||||||
toolchain: stable
|
toolchain: nightly
|
||||||
profile: minimal
|
|
||||||
components: rustfmt
|
components: rustfmt
|
||||||
- name: Check formatting
|
override: true
|
||||||
uses: actions-rs/cargo@v1
|
- uses: LoliGothick/rustfmt-check@v0.2
|
||||||
with:
|
with:
|
||||||
command: fmt
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
args: --all -- --check
|
flags: --all
|
||||||
|
options: --manifest-path=Cargo.toml
|
||||||
|
|
||||||
build:
|
build_and_test:
|
||||||
name: Build
|
name: Build & test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- uses: actions/checkout@v2
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Install Rust toolchain
|
- uses: actions-rs/toolchain@v1
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
with:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
profile: minimal
|
components: clippy
|
||||||
- name: Install Wasm Rust toolchain
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
target: wasm32-unknown-unknown
|
|
||||||
- uses: Swatinem/rust-cache@v1
|
|
||||||
with:
|
|
||||||
sharedKey: ci
|
|
||||||
- uses: actions-rs/cargo@v1
|
- uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: build
|
command: build
|
||||||
args: --all-features --workspace
|
args: --release --all-features
|
||||||
|
|
||||||
test:
|
- uses: actions-rs/clippy-check@v1
|
||||||
needs: build
|
|
||||||
name: Test Suite
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Install Rust toolchain
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
with:
|
||||||
toolchain: stable
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
profile: minimal
|
args: --tests -- -D warnings
|
||||||
- uses: awalsh128/cache-apt-pkgs-action@v1
|
|
||||||
with:
|
|
||||||
packages: taskwarrior
|
|
||||||
version: 1.0
|
|
||||||
- uses: Swatinem/rust-cache@v1
|
|
||||||
with:
|
|
||||||
sharedKey: ci
|
|
||||||
- uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: test
|
|
||||||
args: --all-features --workspace
|
|
||||||
|
|
||||||
clippy:
|
|
||||||
needs: build
|
|
||||||
name: Clippy
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Install Rust toolchain
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
components: clippy
|
|
||||||
- uses: Swatinem/rust-cache@v1
|
|
||||||
with:
|
|
||||||
sharedKey: ci
|
|
||||||
- name: Clippy check
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: clippy
|
|
||||||
args: --all-targets --all-features --workspace -- -D warnings
|
|
||||||
|
|
||||||
coverage:
|
|
||||||
name: Code coverage
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Install Rust toolchain
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
- uses: awalsh128/cache-apt-pkgs-action@v1
|
|
||||||
with:
|
|
||||||
packages: taskwarrior
|
|
||||||
version: 1.0
|
|
||||||
- uses: Swatinem/rust-cache@v1
|
|
||||||
- name: Run cargo-tarpaulin
|
- name: Run cargo-tarpaulin
|
||||||
uses: actions-rs/tarpaulin@v0.1
|
uses: ./.github/actions/cargo-tarpaulin-action/
|
||||||
with:
|
with:
|
||||||
args: '--all-features --workspace --ignore-tests --out Lcov'
|
args: '-- --test-threads 1'
|
||||||
- name: Upload to Coveralls
|
|
||||||
# upload only if push
|
- name: Upload to codecov.io
|
||||||
if: ${{ github.event_name == 'push' }}
|
uses: codecov/codecov-action@v1.0.2
|
||||||
uses: coverallsapp/github-action@master
|
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{secrets.CODECOV_TOKEN}}
|
||||||
path-to-lcov: './lcov.info'
|
|
||||||
|
- name: Archive code coverage results
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: code-coverage-report
|
||||||
|
path: cobertura.xml
|
||||||
|
|||||||
@@ -1,3 +1 @@
|
|||||||
/target
|
/target
|
||||||
api/config/local.*
|
|
||||||
web/dist
|
|
||||||
|
|||||||
+5
-20
@@ -1,23 +1,8 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: local
|
- repo: https://github.com/doublify/pre-commit-rust
|
||||||
|
rev: v1.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: format
|
- id: fmt
|
||||||
name: format
|
- id: cargo-check
|
||||||
language: system
|
args: ['--tests']
|
||||||
pass_filenames: false
|
|
||||||
entry: cargo make format-flow
|
|
||||||
- id: format-toml
|
|
||||||
name: format-toml
|
|
||||||
language: system
|
|
||||||
pass_filenames: false
|
|
||||||
entry: cargo make format-toml-flow
|
|
||||||
- id: check
|
|
||||||
name: check
|
|
||||||
language: system
|
|
||||||
pass_filenames: false
|
|
||||||
entry: cargo make check-tests
|
|
||||||
- id: clippy
|
- id: clippy
|
||||||
name: clippy
|
|
||||||
language: system
|
|
||||||
pass_filenames: false
|
|
||||||
entry: cargo make clippy-flow
|
|
||||||
|
|||||||
Generated
+227
-919
File diff suppressed because it is too large
Load Diff
+27
-5
@@ -1,18 +1,40 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "contextswitch"
|
name = "contextswitch-api"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["David Rousselie <david@rousselie.name>"]
|
authors = ["David Rousselie <david@rousselie.name>"]
|
||||||
|
|
||||||
[workspace]
|
|
||||||
members = ["api", "web"]
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
path = "src/main.rs"
|
||||||
|
name = "contextswitch-api"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
contextswitch-types = { git = "https://github.com/dax/contextswitch-types.git" }
|
||||||
|
actix-web = "=4.0.0-beta.19"
|
||||||
|
actix-http = "=3.0.0-beta.18"
|
||||||
|
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||||
|
serde = { version = "1.0.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
uuid = { version = "0.8.0", features = ["serde"] }
|
uuid = { version = "0.8.0", features = ["serde"] }
|
||||||
chrono = { version = "0.4.0", features = ["serde"] }
|
chrono = { version = "0.4.0", features = ["serde"] }
|
||||||
|
mktemp = "0.4.0"
|
||||||
|
configparser = "3.0.0"
|
||||||
|
dotenv = "0.15.0"
|
||||||
|
listenfd = "0.3.0"
|
||||||
|
tracing = { version = "0.1.0", features = ["log"] }
|
||||||
|
tracing-subscriber = { version = "0.3.0", features = ["std", "env-filter", "fmt", "json"] }
|
||||||
|
tracing-log = "0.1.0"
|
||||||
|
tracing-actix-web = "=0.5.0-beta.9"
|
||||||
|
regex = "1.5.0"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
tracing-bunyan-formatter = "0.3.0"
|
||||||
|
thiserror = "1.0"
|
||||||
|
anyhow = "1.0"
|
||||||
http = "0.2.0"
|
http = "0.2.0"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
reqwest = { version = "0.11.0", features = ["json"] }
|
||||||
|
rstest = "0.12.0"
|
||||||
|
|||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
FROM lukemathwalker/cargo-chef:latest-rust-1.57.0 as chef
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
FROM chef as planner
|
|
||||||
COPY . .
|
|
||||||
RUN cargo chef prepare --recipe-path recipe.json
|
|
||||||
|
|
||||||
FROM chef as builder
|
|
||||||
RUN cargo install cargo-make
|
|
||||||
RUN cargo install trunk
|
|
||||||
RUN rustup target add wasm32-unknown-unknown
|
|
||||||
COPY --from=planner /app/recipe.json recipe.json
|
|
||||||
RUN cargo chef cook -p contextswitch --release --recipe-path recipe.json
|
|
||||||
RUN cargo chef cook -p contextswitch-api --release --recipe-path recipe.json
|
|
||||||
RUN cargo chef cook -p contextswitch-web --release --recipe-path recipe.json --target wasm32-unknown-unknown
|
|
||||||
COPY . .
|
|
||||||
RUN cargo make build-release
|
|
||||||
RUN sed -i 's#http://localhost:8000/api#/api#' web/dist/snippets/contextswitch-web-*/js/api.js
|
|
||||||
|
|
||||||
FROM debian:bullseye-slim AS runtime
|
|
||||||
WORKDIR /app
|
|
||||||
RUN mkdir /data
|
|
||||||
RUN apt-get update -y \
|
|
||||||
&& apt-get install -y --no-install-recommends openssl taskwarrior \
|
|
||||||
&& apt-get autoremove -y \
|
|
||||||
&& apt-get clean -y \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
COPY --from=builder /app/target/release/contextswitch-api contextswitch
|
|
||||||
COPY --from=builder /app/api/config/default.toml config/default.toml
|
|
||||||
COPY --from=builder /app/web/dist/ .
|
|
||||||
ENV CS_TASKWARRIOR.DATA_LOCATION /data
|
|
||||||
ENV CS_APPLICATION.API_PATH /api
|
|
||||||
ENV CS_APPLICATION.STATIC_PATH /
|
|
||||||
CMD ["/app/contextswitch"]
|
|
||||||
@@ -1,201 +1,661 @@
|
|||||||
Apache License
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
Version 2.0, January 2004
|
Version 3, 19 November 2007
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
1. Definitions.
|
Preamble
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
The licenses for most software and other practical works are designed
|
||||||
the copyright owner that is granting the License.
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
When we speak of free software, we are referring to freedom, not
|
||||||
other entities that control, are controlled by, or are under common
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
control with that entity. For the purposes of this definition,
|
have the freedom to distribute copies of free software (and charge for
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
them if you wish), that you receive source code or can get it if you
|
||||||
direction or management of such entity, whether by contract or
|
want it, that you can change the software or use pieces of it in new
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
free programs, and that you know you can do these things.
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
Developers that use our General Public Licenses protect your rights
|
||||||
exercising permissions granted by this License.
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
A secondary benefit of defending all users' freedom is that
|
||||||
including but not limited to software source code, documentation
|
improvements made in alternate versions of the program, if they
|
||||||
source, and configuration files.
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
The GNU Affero General Public License is designed specifically to
|
||||||
transformation or translation of a Source form, including but
|
ensure that, in such cases, the modified source code becomes available
|
||||||
not limited to compiled object code, generated documentation,
|
to the community. It requires the operator of a network server to
|
||||||
and conversions to other media types.
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
An older license, called the Affero General Public License and
|
||||||
Object form, made available under the License, as indicated by a
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
copyright notice that is included in or attached to the work
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
(an example is provided in the Appendix below).
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
The precise terms and conditions for copying, distribution and
|
||||||
form, that is based on (or derived from) the Work and for which the
|
modification follow.
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
TERMS AND CONDITIONS
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
0. Definitions.
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
works, such as semiconductor masks.
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
modifications, and in Source or Object form, provided that You
|
"recipients" may be individuals or organizations.
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
Derivative Works a copy of this License; and
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
A "covered work" means either the unmodified Program or a work based
|
||||||
stating that You changed the files; and
|
on the Program.
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
To "propagate" a work means to do anything with it that, without
|
||||||
that You distribute, all copyright, patent, trademark, and
|
permission, would make you directly or secondarily liable for
|
||||||
attribution notices from the Source form of the Work,
|
infringement under applicable copyright law, except executing it on a
|
||||||
excluding those notices that do not pertain to any part of
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
the Derivative Works; and
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
To "convey" a work means any kind of propagation that enables other
|
||||||
distribution, then any Derivative Works that You distribute must
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
include a readable copy of the attribution notices contained
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
may provide additional or different license terms and conditions
|
to the extent that it includes a convenient and prominently visible
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
tells the user that there is no warranty for the work (except to the
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
extent that warranties are provided), that licensees may convey the
|
||||||
the conditions stated in this License.
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
1. Source Code.
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
The "source code" for a work means the preferred form of the work
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
for making modifications to it. "Object code" means any non-source
|
||||||
except as required for reasonable and customary use in describing the
|
form of a work.
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
A "Standard Interface" means an interface that either is an official
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
standard defined by a recognized standards body, or, in the case of
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
interfaces specified for a particular programming language, one that
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
is widely used among developers working in that language.
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
The "System Libraries" of an executable work include anything, other
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
unless required by applicable law (such as deliberate and grossly
|
packaging a Major Component, but which is not part of that Major
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
Component, and (b) serves only to enable use of the work with that
|
||||||
liable to You for damages, including any direct, indirect, special,
|
Major Component, or to implement a Standard Interface for which an
|
||||||
incidental, or consequential damages of any character arising as a
|
implementation is available to the public in source code form. A
|
||||||
result of this License or out of the use or inability to use the
|
"Major Component", in this context, means a major essential component
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
(kernel, window system, and so on) of the specific operating system
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
other commercial damages or losses), even if such Contributor
|
produce the work, or an object code interpreter used to run it.
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
The "Corresponding Source" for a work in object code form means all
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
the source code needed to generate, install, and (for an executable
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
work) run the object code and to modify the work, including scripts to
|
||||||
or other liability obligations and/or rights consistent with this
|
control those activities. However, it does not include the work's
|
||||||
License. However, in accepting such obligations, You may act only
|
System Libraries, or general-purpose tools or generally available free
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
programs which are used unmodified in performing those activities but
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
which are not part of the work. For example, Corresponding Source
|
||||||
defend, and hold each Contributor harmless for any liability
|
includes interface definition files associated with source files for
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
the work, and the source code for shared libraries and dynamically
|
||||||
of your accepting any such warranty or additional liability.
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
If you develop a new program, and you want it to be of the greatest
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
possible use to the public, the best way to achieve this is to make it
|
||||||
replaced with your own identifying information. (Don't include
|
free software which everyone can redistribute and change under these terms.
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright 2022 David Rousselie
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
you may not use this file except in compliance with the License.
|
Copyright (C) <year> <name of author>
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
This program is distributed in the hope that it will be useful,
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
See the License for the specific language governing permissions and
|
GNU Affero General Public License for more details.
|
||||||
limitations under the License.
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
[env]
|
|
||||||
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = "true"
|
|
||||||
CARGO_MAKE_COVERAGE_PROVIDER = "tarpaulin"
|
|
||||||
CARGO_MAKE_CLIPPY_ARGS = "--tests -- -D warnings"
|
|
||||||
|
|
||||||
[tasks.default]
|
|
||||||
clear = true
|
|
||||||
alias = "watch"
|
|
||||||
|
|
||||||
[tasks.test]
|
|
||||||
install_crate = "cargo-nextest"
|
|
||||||
args = [
|
|
||||||
"nextest",
|
|
||||||
"run",
|
|
||||||
"@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)",
|
|
||||||
"@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )",
|
|
||||||
]
|
|
||||||
|
|
||||||
[tasks.audit]
|
|
||||||
condition = {}
|
|
||||||
workspace = false
|
|
||||||
|
|
||||||
[tasks.run-api]
|
|
||||||
command = "bash"
|
|
||||||
args = ["-c", "cd api; cargo make run"]
|
|
||||||
workspace = false
|
|
||||||
watch = { watch = ["./api/"], no_git_ignore = true }
|
|
||||||
|
|
||||||
[tasks.run-web]
|
|
||||||
command = "bash"
|
|
||||||
args = ["-c", "cd web; cargo make run"]
|
|
||||||
workspace = false
|
|
||||||
|
|
||||||
[tasks.run]
|
|
||||||
run_task = { name = ["run-api", "run-web"], parallel = true, fork = true }
|
|
||||||
workspace = false
|
|
||||||
|
|
||||||
[tasks.watch-api]
|
|
||||||
command = "bash"
|
|
||||||
args = ["-c", "cd api; cargo make dev-test-flow"]
|
|
||||||
workspace = false
|
|
||||||
watch = { watch = ["./api/"], no_git_ignore = true }
|
|
||||||
|
|
||||||
[tasks.watch-web]
|
|
||||||
command = "bash"
|
|
||||||
args = ["-c", "cd web; cargo make dev-test-flow"]
|
|
||||||
workspace = false
|
|
||||||
watch = { watch = ["./web/"], no_git_ignore = true }
|
|
||||||
|
|
||||||
[tasks.watch-root]
|
|
||||||
watch = { watch = ["./src/"], no_git_ignore = true }
|
|
||||||
run_task = "dev-test-flow"
|
|
||||||
workspace = false
|
|
||||||
|
|
||||||
[tasks.watch]
|
|
||||||
run_task = { name = ["watch-api", "watch-web", "watch-root"], parallel = true, fork = true }
|
|
||||||
workspace = false
|
|
||||||
@@ -1,100 +1,2 @@
|
|||||||
# Contextswitch
|
# contextswitch
|
||||||
|
|
||||||
[](https://www.apache.org/licenses/)
|
|
||||||
[](https://coveralls.io/github/dax/contextswitch?branch=main)
|
|
||||||
[](https://github.com/dax/contextswitch/actions)
|
|
||||||
|
|
||||||
Contextswitch is a todo list application linking bookmarks to a task.
|
|
||||||
Integrations with third parties applications add context to a task:
|
|
||||||
- a link to a note taking application to add notes to a task
|
|
||||||
- a link to a Slack thread
|
|
||||||
- a link to a Github issue, pull request or discussion related to the task
|
|
||||||
- ...
|
|
||||||
|
|
||||||
It is intended to be based on existing todo applications and augment them.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- [X] list tasks
|
|
||||||
- [ ] add a task
|
|
||||||
- [ ] add a bookmark to a task
|
|
||||||
- [ ] augment a task with third party integration
|
|
||||||
- [ ] update a task status (waiting, done, ...)
|
|
||||||
- [ ] schedule a task
|
|
||||||
- [ ] update a task status based on bookmarks notifications
|
|
||||||
|
|
||||||
### Integrations
|
|
||||||
|
|
||||||
Todo application backend:
|
|
||||||
- [X] taskwarrior
|
|
||||||
- [ ] todoist
|
|
||||||
|
|
||||||
Third parties integrations:
|
|
||||||
- [ ] Github
|
|
||||||
- [ ] Slack
|
|
||||||
|
|
||||||
Frontend integrations:
|
|
||||||
- [X] Contextswitch
|
|
||||||
- [ ] [Sidebery](https://github.com/mbnuqw/sidebery) Firefox add-ons
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
### Using cargo (for development)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cargo make run
|
|
||||||
```
|
|
||||||
|
|
||||||
### Manual
|
|
||||||
|
|
||||||
1. Get the code
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/dax/contextswitch
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Build api and web release assets
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cargo make build-release
|
|
||||||
```
|
|
||||||
|
|
||||||
It will produce a `target/release/contextswitch-api` backend binary and frontend assets in the `web/dist` directory.
|
|
||||||
|
|
||||||
3. Deploy assets
|
|
||||||
|
|
||||||
```bash
|
|
||||||
mkdir -p $DEPLOY_DIR/config
|
|
||||||
cp -a target/release/contextswitch-api $DEPLOY_DIR
|
|
||||||
cp -a web/dist/* $DEPLOY_DIR
|
|
||||||
cp -a api/config/{default.toml, prod.toml} $DEPLOY_DIR/config
|
|
||||||
```
|
|
||||||
|
|
||||||
4. Run server
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd $DEPLOY_DIR
|
|
||||||
env CONFIG_FILE=$DEPLOY_DIR/config/prod.toml ./contextswitch-api
|
|
||||||
```
|
|
||||||
|
|
||||||
### Using Docker
|
|
||||||
|
|
||||||
#### Build Docker image
|
|
||||||
|
|
||||||
```bash
|
|
||||||
docker build -t contextswitch .
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Run Contextswitch using Docker
|
|
||||||
|
|
||||||
```bash
|
|
||||||
docker run --rm -ti -p 8000:8000 contextswitch
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Access Contextswitch using [http://localhost:8000](http://localhost:8000)
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
[AGPL](LICENSE)
|
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "contextswitch-api"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
authors = ["David Rousselie <david@rousselie.name>"]
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
path = "src/main.rs"
|
|
||||||
name = "contextswitch-api"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
contextswitch = { path = ".." }
|
|
||||||
actix-web = "4.0.0"
|
|
||||||
actix-http = "3.0.0"
|
|
||||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
|
||||||
serde = { version = "1.0.0", features = ["derive"] }
|
|
||||||
serde_json = "1.0"
|
|
||||||
uuid = { version = "0.8.0", features = ["serde"] }
|
|
||||||
chrono = { version = "0.4.0", features = ["serde"] }
|
|
||||||
mktemp = "0.4.0"
|
|
||||||
configparser = "3.0.0"
|
|
||||||
tracing = { version = "0.1.0", features = ["log"] }
|
|
||||||
tracing-subscriber = { version = "0.3.0", features = [
|
|
||||||
"std",
|
|
||||||
"env-filter",
|
|
||||||
"fmt",
|
|
||||||
"json",
|
|
||||||
] }
|
|
||||||
tracing-log = "0.1.0"
|
|
||||||
tracing-actix-web = "0.5.0"
|
|
||||||
regex = "1.5.0"
|
|
||||||
lazy_static = "1.4.0"
|
|
||||||
tracing-bunyan-formatter = "0.3.0"
|
|
||||||
thiserror = "1.0"
|
|
||||||
anyhow = "1.0"
|
|
||||||
http = "0.2.0"
|
|
||||||
config = "0.12.0"
|
|
||||||
actix-files = "0.6.0"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
proptest = "1.0.0"
|
|
||||||
reqwest = { version = "0.11.0", features = ["json"] }
|
|
||||||
rstest = "0.12.0"
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
extend = "../Makefile.toml"
|
|
||||||
|
|
||||||
[tasks.run]
|
|
||||||
clear = true
|
|
||||||
install_crate = { crate_name = "bunyan", binary = "bunyan" }
|
|
||||||
env = { "TASKRC" = "$PWD/taskrc" }
|
|
||||||
command = "bash"
|
|
||||||
args = ["-c", "cargo run | bunyan"]
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
[application]
|
|
||||||
port = 8000
|
|
||||||
# See https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html
|
|
||||||
log_directive = "info"
|
|
||||||
api_path = ""
|
|
||||||
front_base_url = "http://localhost:8080"
|
|
||||||
|
|
||||||
[taskwarrior]
|
|
||||||
data_location = "/tmp"
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
[application]
|
|
||||||
log_directive = "debug"
|
|
||||||
static_dir = "../web/dist"
|
|
||||||
api_path = "/api"
|
|
||||||
static_path = ""
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
[application]
|
|
||||||
static_dir = "."
|
|
||||||
api_path = "/api"
|
|
||||||
static_path = ""
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
[application]
|
|
||||||
log_directive = "debug"
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
use config::{Config, ConfigError, Environment, File};
|
|
||||||
use serde::Deserialize;
|
|
||||||
use std::env;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct Settings {
|
|
||||||
pub application: ApplicationSettings,
|
|
||||||
pub taskwarrior: TaskwarriorSettings,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct ApplicationSettings {
|
|
||||||
pub port: u16,
|
|
||||||
pub log_directive: String,
|
|
||||||
pub front_base_url: String,
|
|
||||||
pub api_path: String,
|
|
||||||
pub static_path: Option<String>,
|
|
||||||
pub static_dir: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct TaskwarriorSettings {
|
|
||||||
pub data_location: Option<String>,
|
|
||||||
pub taskrc: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Settings {
|
|
||||||
pub fn new_from_file(file: Option<String>) -> Result<Self, ConfigError> {
|
|
||||||
let config_file_required = file.is_some();
|
|
||||||
let config_path = env::var("CONFIG_PATH").unwrap_or_else(|_| "config".into());
|
|
||||||
let config_file = file.unwrap_or_else(|| {
|
|
||||||
env::var("CONFIG_FILE").unwrap_or_else(|_| format!("{}/dev", &config_path))
|
|
||||||
});
|
|
||||||
|
|
||||||
let default_config_file = format!("{}/default", config_path);
|
|
||||||
let local_config_file = format!("{}/local", config_path);
|
|
||||||
println!(
|
|
||||||
"Trying to load {:?} config files",
|
|
||||||
vec![&default_config_file, &local_config_file, &config_file]
|
|
||||||
);
|
|
||||||
|
|
||||||
let config = Config::builder()
|
|
||||||
.add_source(File::with_name(&default_config_file))
|
|
||||||
.add_source(File::with_name(&local_config_file).required(false))
|
|
||||||
.add_source(File::with_name(&config_file).required(config_file_required))
|
|
||||||
.add_source(Environment::with_prefix("cs"))
|
|
||||||
.build()?;
|
|
||||||
|
|
||||||
config.try_deserialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new() -> Result<Self, ConfigError> {
|
|
||||||
Settings::new_from_file(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,633 +0,0 @@
|
|||||||
use crate::configuration::TaskwarriorSettings;
|
|
||||||
use anyhow::{anyhow, Context};
|
|
||||||
use chrono::{DateTime, Utc};
|
|
||||||
use configparser::ini::Ini;
|
|
||||||
use contextswitch::{ContextswitchData, Task, TaskId};
|
|
||||||
use regex::Regex;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use serde_json;
|
|
||||||
use std::env;
|
|
||||||
use std::fmt;
|
|
||||||
use std::path::Path;
|
|
||||||
use std::process::Command;
|
|
||||||
use std::str;
|
|
||||||
use tokio::sync::Mutex;
|
|
||||||
use tracing::{debug, warn};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::ContextswitchError;
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug")]
|
|
||||||
pub fn list_tasks(filters: Vec<&str>) -> Result<Vec<TaskwarriorTask>, TaskwarriorError> {
|
|
||||||
let args = [filters, vec!["export"]].concat();
|
|
||||||
let export_output = Command::new("task")
|
|
||||||
.args(args)
|
|
||||||
.output()
|
|
||||||
.map_err(TaskwarriorError::ExecutionError)?;
|
|
||||||
|
|
||||||
let output =
|
|
||||||
String::from_utf8(export_output.stdout).context("Failed to read Taskwarrior output")?;
|
|
||||||
|
|
||||||
let tasks: Vec<TaskwarriorTask> = serde_json::from_str(&output)
|
|
||||||
.map_err(|e| TaskwarriorError::OutputParsingError { source: e, output })?;
|
|
||||||
|
|
||||||
Ok(tasks)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug")]
|
|
||||||
pub fn get_task_by_local_id(
|
|
||||||
id: &TaskwarriorTaskLocalId,
|
|
||||||
) -> Result<Option<TaskwarriorTask>, TaskwarriorError> {
|
|
||||||
let mut tasks: Vec<TaskwarriorTask> = list_tasks(vec![&id.to_string()])?;
|
|
||||||
if tasks.len() > 1 {
|
|
||||||
return Err(TaskwarriorError::UnexpectedError(anyhow!(
|
|
||||||
"Found more than 1 task when searching for task with local ID {}",
|
|
||||||
id
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(tasks.pop())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug")]
|
|
||||||
pub fn get_task_by_id(
|
|
||||||
uuid: &TaskwarriorTaskId,
|
|
||||||
) -> Result<Option<TaskwarriorTask>, TaskwarriorError> {
|
|
||||||
let mut tasks: Vec<TaskwarriorTask> = list_tasks(vec![&uuid.to_string()])?;
|
|
||||||
if tasks.len() > 1 {
|
|
||||||
return Err(TaskwarriorError::UnexpectedError(anyhow!(
|
|
||||||
"Found more than 1 task when searching for task with UUID {}",
|
|
||||||
uuid
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(tasks.pop())
|
|
||||||
}
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref RE: Regex = Regex::new(r"Modified 1 task.").unwrap();
|
|
||||||
static ref TW_WRITE_LOCK: Mutex<u32> = Mutex::new(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug")]
|
|
||||||
pub async fn add_task(add_args: Vec<&str>) -> Result<TaskwarriorTask, TaskwarriorError> {
|
|
||||||
lazy_static! {
|
|
||||||
static ref RE: Regex = Regex::new(r"Created task (?P<id>\d+).").unwrap();
|
|
||||||
}
|
|
||||||
let _lock = TW_WRITE_LOCK.lock().await;
|
|
||||||
|
|
||||||
let args = [vec!["add"], add_args].concat();
|
|
||||||
let add_output = Command::new("task")
|
|
||||||
.args(args)
|
|
||||||
.output()
|
|
||||||
.map_err(TaskwarriorError::ExecutionError)?;
|
|
||||||
let output =
|
|
||||||
String::from_utf8(add_output.stdout).context("Failed to read Taskwarrior output")?;
|
|
||||||
let task_id_capture = RE
|
|
||||||
.captures(&output)
|
|
||||||
.ok_or_else(|| anyhow!("Cannot extract task ID from: {}", &output))?;
|
|
||||||
let task_id_str = task_id_capture
|
|
||||||
.name("id")
|
|
||||||
.ok_or_else(|| anyhow!("Cannot extract task ID value from: {}", &output))?
|
|
||||||
.as_str();
|
|
||||||
|
|
||||||
let task_id = TaskwarriorTaskLocalId(
|
|
||||||
task_id_str
|
|
||||||
.parse::<u64>()
|
|
||||||
.context("Cannot parse task ID value")?,
|
|
||||||
);
|
|
||||||
|
|
||||||
let task = get_task_by_local_id(&task_id)?;
|
|
||||||
task.ok_or_else(|| {
|
|
||||||
TaskwarriorError::UnexpectedError(anyhow!(
|
|
||||||
"Newly created task with ID {} was not found",
|
|
||||||
task_id
|
|
||||||
))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug")]
|
|
||||||
pub async fn update_task(action: TaskwarriorAction) -> Result<TaskwarriorTask, TaskwarriorError> {
|
|
||||||
lazy_static! {
|
|
||||||
static ref RE: Regex = Regex::new(r"Modified 1 task.").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let _lock = TW_WRITE_LOCK.lock().await;
|
|
||||||
let args = [
|
|
||||||
vec![action.uuid.to_string(), "mod".to_string()],
|
|
||||||
action.args,
|
|
||||||
]
|
|
||||||
.concat();
|
|
||||||
Command::new("task")
|
|
||||||
.args(args)
|
|
||||||
.output()
|
|
||||||
.map_err(TaskwarriorError::ExecutionError)?;
|
|
||||||
|
|
||||||
let updated_task = get_task_by_id(&action.uuid)?;
|
|
||||||
updated_task.ok_or_else(|| {
|
|
||||||
TaskwarriorError::UnexpectedError(anyhow!(
|
|
||||||
"Updated task with UUID {} was not found",
|
|
||||||
action.uuid
|
|
||||||
))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Types
|
|
||||||
// TaskwarriorTask
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
|
|
||||||
pub struct TaskwarriorTaskLocalId(pub u64);
|
|
||||||
|
|
||||||
impl fmt::Display for TaskwarriorTaskLocalId {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
|
|
||||||
pub struct TaskwarriorTaskId(pub Uuid);
|
|
||||||
|
|
||||||
impl fmt::Display for TaskwarriorTaskId {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<TaskwarriorTaskId> for TaskId {
|
|
||||||
fn from(task: TaskwarriorTaskId) -> Self {
|
|
||||||
TaskId(task.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<TaskId> for TaskwarriorTaskId {
|
|
||||||
fn from(task: TaskId) -> Self {
|
|
||||||
TaskwarriorTaskId(task.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
pub struct TaskwarriorTask {
|
|
||||||
pub uuid: TaskwarriorTaskId,
|
|
||||||
pub id: TaskwarriorTaskLocalId,
|
|
||||||
#[serde(with = "contextswitch::tw_date_format")]
|
|
||||||
pub entry: DateTime<Utc>,
|
|
||||||
#[serde(with = "contextswitch::tw_date_format")]
|
|
||||||
pub modified: DateTime<Utc>,
|
|
||||||
pub status: contextswitch::Status,
|
|
||||||
pub description: String,
|
|
||||||
pub urgency: f64,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "contextswitch::opt_tw_date_format"
|
|
||||||
)]
|
|
||||||
pub due: Option<DateTime<Utc>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "contextswitch::opt_tw_date_format"
|
|
||||||
)]
|
|
||||||
pub start: Option<DateTime<Utc>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "contextswitch::opt_tw_date_format"
|
|
||||||
)]
|
|
||||||
pub end: Option<DateTime<Utc>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "contextswitch::opt_tw_date_format"
|
|
||||||
)]
|
|
||||||
pub wait: Option<DateTime<Utc>>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub parent: Option<TaskwarriorTaskId>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub project: Option<String>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub priority: Option<contextswitch::Priority>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub recur: Option<contextswitch::Recurrence>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub tags: Option<Vec<String>>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub contextswitch: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<TaskwarriorTask> for Task {
|
|
||||||
fn from(task: TaskwarriorTask) -> Self {
|
|
||||||
(&task).into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&TaskwarriorTask> for Task {
|
|
||||||
fn from(task: &TaskwarriorTask) -> Self {
|
|
||||||
let cs_data =
|
|
||||||
task.contextswitch
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|cs_string| -> Option<ContextswitchData> {
|
|
||||||
let contextswitch_data_result = serde_json::from_str(cs_string);
|
|
||||||
if contextswitch_data_result.is_err() {
|
|
||||||
warn!(
|
|
||||||
"Invalid Contextswitch data found in {}: {}",
|
|
||||||
&task.uuid, cs_string
|
|
||||||
);
|
|
||||||
}
|
|
||||||
contextswitch_data_result.ok()
|
|
||||||
});
|
|
||||||
|
|
||||||
Task {
|
|
||||||
id: task.uuid.clone().into(),
|
|
||||||
entry: task.entry,
|
|
||||||
modified: task.modified,
|
|
||||||
status: task.status,
|
|
||||||
description: task.description.clone(),
|
|
||||||
urgency: task.urgency,
|
|
||||||
due: task.due,
|
|
||||||
start: task.start,
|
|
||||||
end: task.end,
|
|
||||||
wait: task.wait,
|
|
||||||
parent: task.parent.clone().map(|id| id.into()),
|
|
||||||
project: task.project.clone(),
|
|
||||||
priority: task.priority,
|
|
||||||
recur: task.recur,
|
|
||||||
tags: task.tags.clone(),
|
|
||||||
contextswitch: cs_data,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TaskwarriorAction
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct TaskwarriorAction {
|
|
||||||
pub uuid: TaskwarriorTaskId,
|
|
||||||
pub args: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_arg(arg: &str) -> impl Fn(String) -> String + '_ {
|
|
||||||
move |value: String| format!("{}:{}", arg, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn format_date(date: DateTime<Utc>) -> String {
|
|
||||||
date.format("%Y-%m-%dT%H:%M:%SZ").to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<Task> for TaskwarriorAction {
|
|
||||||
type Error = ContextswitchError;
|
|
||||||
|
|
||||||
fn try_from(task: Task) -> Result<Self, Self::Error> {
|
|
||||||
(&task).try_into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn format_json<T>(data_opt: &Option<T>) -> Result<Option<String>, ContextswitchError>
|
|
||||||
where
|
|
||||||
T: Sized + Serialize,
|
|
||||||
{
|
|
||||||
data_opt
|
|
||||||
.as_ref()
|
|
||||||
.map(|data| serde_json::to_string(data).map_err(ContextswitchError::InvalidDataError))
|
|
||||||
.transpose()
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<&Task> for TaskwarriorAction {
|
|
||||||
type Error = ContextswitchError;
|
|
||||||
|
|
||||||
fn try_from(task: &Task) -> Result<Self, Self::Error> {
|
|
||||||
let args = vec![task.description.clone()];
|
|
||||||
let tags_args = task
|
|
||||||
.tags
|
|
||||||
.clone()
|
|
||||||
.map(|tags| {
|
|
||||||
tags.iter()
|
|
||||||
.map(|tag| format!("+{}", tag)) // TODO remove tags
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
})
|
|
||||||
.unwrap_or_else(Vec::new);
|
|
||||||
let opt_args = [
|
|
||||||
task.due
|
|
||||||
.map(format_date)
|
|
||||||
.or_else(|| Some("".to_string()))
|
|
||||||
.map(to_arg("due")),
|
|
||||||
task.start
|
|
||||||
.map(format_date)
|
|
||||||
.or_else(|| Some("".to_string()))
|
|
||||||
.map(to_arg("start")),
|
|
||||||
task.end
|
|
||||||
.map(format_date)
|
|
||||||
.or_else(|| Some("".to_string()))
|
|
||||||
.map(to_arg("end")),
|
|
||||||
task.wait
|
|
||||||
.map(format_date)
|
|
||||||
.or_else(|| Some("".to_string()))
|
|
||||||
.map(to_arg("wait")),
|
|
||||||
task.parent
|
|
||||||
.as_ref()
|
|
||||||
.map(|id| id.to_string())
|
|
||||||
.or_else(|| Some("".to_string()))
|
|
||||||
.map(to_arg("parent")),
|
|
||||||
task.project
|
|
||||||
.clone()
|
|
||||||
.or_else(|| Some("".to_string()))
|
|
||||||
.map(to_arg("project")),
|
|
||||||
task.priority
|
|
||||||
.map(|priority| priority.to_string())
|
|
||||||
.or_else(|| Some("".to_string()))
|
|
||||||
.map(to_arg("priority")),
|
|
||||||
task.recur
|
|
||||||
.map(|recur| recur.to_string())
|
|
||||||
.or_else(|| Some("".to_string()))
|
|
||||||
.map(to_arg("recur")),
|
|
||||||
format_json(&task.contextswitch)?
|
|
||||||
.or_else(|| Some("".to_string()))
|
|
||||||
.map(to_arg("contextswitch")),
|
|
||||||
];
|
|
||||||
|
|
||||||
Ok(TaskwarriorAction {
|
|
||||||
uuid: task.id.clone().into(),
|
|
||||||
args: [
|
|
||||||
args,
|
|
||||||
tags_args,
|
|
||||||
opt_args
|
|
||||||
.iter()
|
|
||||||
.filter_map(|arg| arg.clone())
|
|
||||||
.collect::<Vec<String>>(),
|
|
||||||
]
|
|
||||||
.concat(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Errors
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
|
||||||
pub enum TaskwarriorError {
|
|
||||||
#[error("Error while executing Taskwarrior")]
|
|
||||||
ExecutionError(#[from] std::io::Error),
|
|
||||||
#[error("Error while parsing Taskwarrior output")]
|
|
||||||
OutputParsingError {
|
|
||||||
#[source]
|
|
||||||
source: serde_json::Error,
|
|
||||||
output: String,
|
|
||||||
},
|
|
||||||
#[error(transparent)]
|
|
||||||
UnexpectedError(#[from] anyhow::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Taskwarrior config functions
|
|
||||||
fn write_default_config(data_location: &str) -> String {
|
|
||||||
let mut taskrc = Ini::new();
|
|
||||||
taskrc.setstr("default", "data.location", Some(data_location));
|
|
||||||
taskrc.setstr("default", "uda.contextswitch.type", Some("string"));
|
|
||||||
taskrc.setstr(
|
|
||||||
"default",
|
|
||||||
"uda.contextswitch.label",
|
|
||||||
Some("Contextswitch data"),
|
|
||||||
);
|
|
||||||
taskrc.setstr("default", "uda.contextswitch.default", Some("{}"));
|
|
||||||
|
|
||||||
let taskrc_path = Path::new(&data_location).join(".taskrc");
|
|
||||||
let taskrc_location = taskrc_path.to_str().unwrap();
|
|
||||||
taskrc.write(taskrc_location).unwrap();
|
|
||||||
|
|
||||||
taskrc_location.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load_config(settings: &TaskwarriorSettings) -> String {
|
|
||||||
if let Some(taskrc_location) = &settings.taskrc {
|
|
||||||
let mut taskrc = Ini::new();
|
|
||||||
taskrc
|
|
||||||
.load(&taskrc_location)
|
|
||||||
.unwrap_or_else(|_| panic!("Cannot load taskrc file {}", taskrc_location));
|
|
||||||
let data_location = taskrc.get("default", "data.location").unwrap_or_else(|| {
|
|
||||||
panic!(
|
|
||||||
"'data.location' must be set in taskrc file {}",
|
|
||||||
taskrc_location
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
env::set_var("TASKRC", &taskrc_location);
|
|
||||||
debug!(
|
|
||||||
"Extracted data location `{}` from existing taskrc `{}`",
|
|
||||||
data_location, taskrc_location
|
|
||||||
);
|
|
||||||
|
|
||||||
data_location
|
|
||||||
} else {
|
|
||||||
let data_location = settings
|
|
||||||
.data_location
|
|
||||||
.as_ref()
|
|
||||||
.expect("Expecting taskwarrior.taskrc or taskwarrior.data_location setting to be set")
|
|
||||||
.to_string();
|
|
||||||
let taskrc_location = write_default_config(&data_location);
|
|
||||||
|
|
||||||
env::set_var("TASKRC", &taskrc_location);
|
|
||||||
debug!("Default taskrc written in `{}`", &taskrc_location);
|
|
||||||
|
|
||||||
data_location
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
|
|
||||||
mod from_taskwarrior_task_to_contextswitch_task {
|
|
||||||
use super::super::*;
|
|
||||||
use chrono::TimeZone;
|
|
||||||
use contextswitch::Bookmark;
|
|
||||||
use http::uri::Uri;
|
|
||||||
use proptest::prelude::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_successful_full_convertion() {
|
|
||||||
let tw_task = TaskwarriorTask {
|
|
||||||
uuid: TaskwarriorTaskId(Uuid::new_v4()),
|
|
||||||
id: TaskwarriorTaskLocalId(42),
|
|
||||||
entry: Utc.ymd(2022, 1, 1).and_hms(1, 0, 0),
|
|
||||||
modified: Utc.ymd(2022, 1, 1).and_hms(1, 0, 1),
|
|
||||||
status: contextswitch::Status::Pending,
|
|
||||||
description: "simple task".to_string(),
|
|
||||||
urgency: 0.5,
|
|
||||||
due: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 2)),
|
|
||||||
start: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 3)),
|
|
||||||
end: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 4)),
|
|
||||||
wait: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 5)),
|
|
||||||
parent: Some(TaskwarriorTaskId(Uuid::new_v4())),
|
|
||||||
project: Some("simple project".to_string()),
|
|
||||||
priority: Some(contextswitch::Priority::H),
|
|
||||||
recur: Some(contextswitch::Recurrence::Daily),
|
|
||||||
tags: Some(vec!["tag1".to_string(), "tag2".to_string()]),
|
|
||||||
contextswitch: Some(String::from(
|
|
||||||
r#"{"bookmarks": [{"uri": "https://www.example.com/path"}]}"#,
|
|
||||||
)),
|
|
||||||
};
|
|
||||||
let cs_task: Task = (&tw_task).into();
|
|
||||||
|
|
||||||
assert_eq!(tw_task.uuid.0, cs_task.id.0);
|
|
||||||
assert_eq!(tw_task.entry, cs_task.entry);
|
|
||||||
assert_eq!(tw_task.modified, cs_task.modified);
|
|
||||||
assert_eq!(tw_task.status, cs_task.status);
|
|
||||||
assert_eq!(tw_task.description, cs_task.description);
|
|
||||||
assert_eq!(tw_task.urgency, cs_task.urgency);
|
|
||||||
assert_eq!(tw_task.due, cs_task.due);
|
|
||||||
assert_eq!(tw_task.start, cs_task.start);
|
|
||||||
assert_eq!(tw_task.end, cs_task.end);
|
|
||||||
assert_eq!(tw_task.wait, cs_task.wait);
|
|
||||||
assert_eq!(
|
|
||||||
tw_task.parent.map(|id| id.to_string()),
|
|
||||||
cs_task.parent.map(|id| id.to_string())
|
|
||||||
);
|
|
||||||
assert_eq!(tw_task.project, cs_task.project);
|
|
||||||
assert_eq!(tw_task.priority, cs_task.priority);
|
|
||||||
assert_eq!(tw_task.recur, cs_task.recur);
|
|
||||||
assert_eq!(tw_task.tags, cs_task.tags);
|
|
||||||
assert_eq!(
|
|
||||||
Some(ContextswitchData {
|
|
||||||
bookmarks: vec![Bookmark {
|
|
||||||
uri: "https://www.example.com/path".parse::<Uri>().unwrap(),
|
|
||||||
content: None
|
|
||||||
}]
|
|
||||||
}),
|
|
||||||
cs_task.contextswitch
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
proptest! {
|
|
||||||
#[test]
|
|
||||||
fn test_conversion_with_invalid_contextswitch_data_format(cs_data in ".*") {
|
|
||||||
let tw_task = TaskwarriorTask {
|
|
||||||
uuid: TaskwarriorTaskId(Uuid::new_v4()),
|
|
||||||
id: TaskwarriorTaskLocalId(42),
|
|
||||||
entry: Utc.ymd(2022, 1, 1).and_hms(1, 0, 0),
|
|
||||||
modified: Utc.ymd(2022, 1, 1).and_hms(1, 0, 1),
|
|
||||||
status: contextswitch::Status::Pending,
|
|
||||||
description: "simple task".to_string(),
|
|
||||||
urgency: 0.5,
|
|
||||||
due: None,
|
|
||||||
start: None,
|
|
||||||
end: None,
|
|
||||||
wait: None,
|
|
||||||
parent: None,
|
|
||||||
project: None,
|
|
||||||
priority: None,
|
|
||||||
recur: None,
|
|
||||||
tags: None,
|
|
||||||
contextswitch: Some(cs_data),
|
|
||||||
};
|
|
||||||
let cs_task: Task = (&tw_task).into();
|
|
||||||
|
|
||||||
assert_eq!(tw_task.uuid.0, cs_task.id.0);
|
|
||||||
assert_eq!(tw_task.entry, cs_task.entry);
|
|
||||||
assert_eq!(tw_task.modified, cs_task.modified);
|
|
||||||
assert_eq!(tw_task.status, cs_task.status);
|
|
||||||
assert_eq!(tw_task.description, cs_task.description);
|
|
||||||
assert_eq!(tw_task.urgency, cs_task.urgency);
|
|
||||||
assert_eq!(None, cs_task.contextswitch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod from_contextswitch_task_to_taskwarrior_action {
|
|
||||||
use super::super::*;
|
|
||||||
use chrono::TimeZone;
|
|
||||||
use contextswitch::{Bookmark, Priority, Recurrence};
|
|
||||||
use http::Uri;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_successful_convertion() {
|
|
||||||
let task = Task {
|
|
||||||
id: TaskId(Uuid::new_v4()),
|
|
||||||
entry: Utc.ymd(2022, 1, 1).and_hms(1, 0, 0),
|
|
||||||
modified: Utc.ymd(2022, 1, 1).and_hms(1, 0, 1),
|
|
||||||
status: contextswitch::Status::Pending,
|
|
||||||
description: "simple task".to_string(),
|
|
||||||
urgency: 0.5,
|
|
||||||
due: None,
|
|
||||||
start: None,
|
|
||||||
end: None,
|
|
||||||
wait: None,
|
|
||||||
parent: None,
|
|
||||||
project: None,
|
|
||||||
priority: None,
|
|
||||||
recur: None,
|
|
||||||
tags: None,
|
|
||||||
contextswitch: None,
|
|
||||||
};
|
|
||||||
let action: TaskwarriorAction = (&task)
|
|
||||||
.try_into()
|
|
||||||
.expect("Failed to convert Task into TaskwarriorAction");
|
|
||||||
|
|
||||||
assert_eq!(task.id.0, action.uuid.0);
|
|
||||||
assert_eq!(
|
|
||||||
vec![
|
|
||||||
task.description,
|
|
||||||
"due:".to_string(),
|
|
||||||
"start:".to_string(),
|
|
||||||
"end:".to_string(),
|
|
||||||
"wait:".to_string(),
|
|
||||||
"parent:".to_string(),
|
|
||||||
"project:".to_string(),
|
|
||||||
"priority:".to_string(),
|
|
||||||
"recur:".to_string(),
|
|
||||||
"contextswitch:".to_string(),
|
|
||||||
],
|
|
||||||
action.args
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_successful_full_convertion() {
|
|
||||||
let task = Task {
|
|
||||||
id: TaskId(Uuid::new_v4()),
|
|
||||||
entry: Utc.ymd(2022, 1, 1).and_hms(1, 0, 0),
|
|
||||||
modified: Utc.ymd(2022, 1, 1).and_hms(1, 0, 1),
|
|
||||||
status: contextswitch::Status::Pending,
|
|
||||||
description: "simple task".to_string(),
|
|
||||||
urgency: 0.5,
|
|
||||||
due: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 2)),
|
|
||||||
start: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 3)),
|
|
||||||
end: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 4)),
|
|
||||||
wait: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 5)),
|
|
||||||
parent: Some(TaskId(Uuid::new_v4())),
|
|
||||||
project: Some("myproject".to_string()),
|
|
||||||
priority: Some(Priority::H),
|
|
||||||
recur: Some(Recurrence::Monthly),
|
|
||||||
tags: Some(vec!["tag1".to_string(), "tag2".to_string()]),
|
|
||||||
contextswitch: Some(ContextswitchData {
|
|
||||||
bookmarks: vec![
|
|
||||||
Bookmark {
|
|
||||||
uri: "https://www.example.com/path".parse::<Uri>().unwrap(),
|
|
||||||
content: None,
|
|
||||||
},
|
|
||||||
Bookmark {
|
|
||||||
uri: "https://www.example.com/path2".parse::<Uri>().unwrap(),
|
|
||||||
content: None,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
let action: TaskwarriorAction = (&task)
|
|
||||||
.try_into()
|
|
||||||
.expect("Failed to convert Task into TaskwarriorAction");
|
|
||||||
|
|
||||||
assert_eq!(task.id.0, action.uuid.0);
|
|
||||||
assert_eq!(
|
|
||||||
vec![
|
|
||||||
task.description,
|
|
||||||
"+tag1".to_string(),
|
|
||||||
"+tag2".to_string(),
|
|
||||||
"due:2022-01-01T01:00:02Z".to_string(),
|
|
||||||
"start:2022-01-01T01:00:03Z".to_string(),
|
|
||||||
"end:2022-01-01T01:00:04Z".to_string(),
|
|
||||||
"wait:2022-01-01T01:00:05Z".to_string(),
|
|
||||||
format!("parent:{}", task.parent.unwrap()),
|
|
||||||
"project:myproject".to_string(),
|
|
||||||
"priority:H".to_string(),
|
|
||||||
"recur:monthly".to_string(),
|
|
||||||
String::from(
|
|
||||||
r#"contextswitch:{"bookmarks":[{"uri":"https://www.example.com/path"},{"uri":"https://www.example.com/path2"}]}"#
|
|
||||||
)
|
|
||||||
],
|
|
||||||
action.args
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
use actix_files as fs;
|
|
||||||
use actix_web::{dev::Server, http, middleware, web, App, HttpServer};
|
|
||||||
use configuration::Settings;
|
|
||||||
use core::time::Duration;
|
|
||||||
use std::net::TcpListener;
|
|
||||||
use tracing::info;
|
|
||||||
use tracing_actix_web::TracingLogger;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
|
||||||
|
|
||||||
pub mod configuration;
|
|
||||||
pub mod contextswitch;
|
|
||||||
pub mod observability;
|
|
||||||
pub mod routes;
|
|
||||||
|
|
||||||
pub fn run(listener: TcpListener, settings: &Settings) -> Result<Server, std::io::Error> {
|
|
||||||
let api_path = settings.application.api_path.clone();
|
|
||||||
let front_base_url = settings.application.front_base_url.clone();
|
|
||||||
let static_path = settings.application.static_path.clone();
|
|
||||||
let static_dir = settings
|
|
||||||
.application
|
|
||||||
.static_dir
|
|
||||||
.clone()
|
|
||||||
.unwrap_or_else(|| ".".to_string());
|
|
||||||
|
|
||||||
let server = HttpServer::new(move || {
|
|
||||||
info!(
|
|
||||||
"Mounting API on {}",
|
|
||||||
if api_path.is_empty() { "/" } else { &api_path }
|
|
||||||
);
|
|
||||||
let api_scope = web::scope(&api_path)
|
|
||||||
.wrap(
|
|
||||||
middleware::DefaultHeaders::new()
|
|
||||||
.add(("Access-Control-Allow-Origin", front_base_url.as_bytes()))
|
|
||||||
.add((
|
|
||||||
"Access-Control-Allow-Methods",
|
|
||||||
"POST, GET, OPTIONS".as_bytes(),
|
|
||||||
))
|
|
||||||
.add(("Access-Control-Allow-Headers", "content-type".as_bytes())),
|
|
||||||
)
|
|
||||||
.route("/tasks", web::get().to(routes::list_tasks))
|
|
||||||
.route("/tasks", web::post().to(routes::add_task))
|
|
||||||
.route("/tasks/{task_id}", web::put().to(routes::update_task))
|
|
||||||
.route(
|
|
||||||
"/tasks",
|
|
||||||
web::method(http::Method::OPTIONS).to(routes::option_task),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut app = App::new()
|
|
||||||
.wrap(TracingLogger::default())
|
|
||||||
.wrap(middleware::Compress::default())
|
|
||||||
.route("/ping", web::get().to(routes::ping))
|
|
||||||
.service(api_scope);
|
|
||||||
if let Some(path) = &static_path {
|
|
||||||
info!(
|
|
||||||
"Mounting static files on {}",
|
|
||||||
if path.is_empty() { "/" } else { path }
|
|
||||||
);
|
|
||||||
let static_scope = fs::Files::new(path, &static_dir)
|
|
||||||
.use_last_modified(true)
|
|
||||||
.index_file("index.html");
|
|
||||||
app = app.service(static_scope);
|
|
||||||
}
|
|
||||||
app
|
|
||||||
})
|
|
||||||
.keep_alive(http::KeepAlive::Timeout(Duration::from_secs(60)))
|
|
||||||
.shutdown_timeout(60)
|
|
||||||
.listen(listener)?;
|
|
||||||
|
|
||||||
Ok(server.run())
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
use contextswitch_api::configuration::Settings;
|
|
||||||
use contextswitch_api::observability::{get_subscriber, init_subscriber};
|
|
||||||
use contextswitch_api::{contextswitch::taskwarrior, run};
|
|
||||||
use std::net::TcpListener;
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> std::io::Result<()> {
|
|
||||||
let settings = Settings::new().expect("Cannot load Contextswitch configuration");
|
|
||||||
let subscriber = get_subscriber(&settings.application.log_directive);
|
|
||||||
init_subscriber(subscriber);
|
|
||||||
|
|
||||||
taskwarrior::load_config(&settings.taskwarrior);
|
|
||||||
|
|
||||||
let listener = TcpListener::bind(format!("0.0.0.0:{}", settings.application.port))
|
|
||||||
.expect("Failed to bind port");
|
|
||||||
run(listener, &settings)?.await
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
use crate::contextswitch as cs;
|
|
||||||
use actix_web::{http::StatusCode, web, HttpResponse, ResponseError};
|
|
||||||
use anyhow::Context;
|
|
||||||
use contextswitch::{NewTask, Task, TaskId};
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct TaskQuery {
|
|
||||||
filter: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ResponseError for cs::ContextswitchError {
|
|
||||||
fn status_code(&self) -> StatusCode {
|
|
||||||
match self {
|
|
||||||
cs::ContextswitchError::InvalidDataError { .. } => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
cs::ContextswitchError::UnexpectedError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip_all, fields(filter = %task_query.filter.as_ref().unwrap_or(&"".to_string())))]
|
|
||||||
pub async fn list_tasks(
|
|
||||||
task_query: web::Query<TaskQuery>,
|
|
||||||
) -> Result<HttpResponse, cs::ContextswitchError> {
|
|
||||||
let filter = task_query
|
|
||||||
.filter
|
|
||||||
.as_ref()
|
|
||||||
.map_or(vec![], |filter| filter.split(' ').collect());
|
|
||||||
let tasks: Vec<Task> = cs::list_tasks(filter)?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.content_type("application/json")
|
|
||||||
.body(serde_json::to_string(&tasks).context("Cannot serialize Contextswitch task")?))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip_all, fields(definition = %new_task.definition))]
|
|
||||||
pub async fn add_task(
|
|
||||||
new_task: web::Json<NewTask>,
|
|
||||||
) -> Result<HttpResponse, cs::ContextswitchError> {
|
|
||||||
let task: Task = cs::add_task(new_task.definition.split(' ').collect()).await?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.content_type("application/json")
|
|
||||||
.body(serde_json::to_string(&task).context("Cannot serialize Contextswitch task")?))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip_all)]
|
|
||||||
pub async fn update_task(
|
|
||||||
path: web::Path<TaskId>,
|
|
||||||
task: web::Json<Task>,
|
|
||||||
) -> Result<HttpResponse, cs::ContextswitchError> {
|
|
||||||
let task_to_update = task.into_inner();
|
|
||||||
if path.into_inner() != task_to_update.id {
|
|
||||||
return Ok(HttpResponse::BadRequest().finish());
|
|
||||||
}
|
|
||||||
let task_updated: Task = cs::update_task(task_to_update).await?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.content_type("application/json")
|
|
||||||
.body(serde_json::to_string(&task_updated).context("Cannot serialize Contextswitch task")?))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug")]
|
|
||||||
pub async fn option_task() -> HttpResponse {
|
|
||||||
HttpResponse::Ok().finish()
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
use contextswitch_api::configuration::Settings;
|
|
||||||
use contextswitch_api::contextswitch::taskwarrior;
|
|
||||||
use contextswitch_api::observability::{get_subscriber, init_subscriber};
|
|
||||||
use mktemp::Temp;
|
|
||||||
use rstest::*;
|
|
||||||
use std::net::TcpListener;
|
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
fn setup_tracing(settings: &Settings) {
|
|
||||||
info!("Setting up tracing");
|
|
||||||
let subscriber = get_subscriber(&settings.application.log_directive);
|
|
||||||
init_subscriber(subscriber);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn setup_server(settings: &Settings) -> String {
|
|
||||||
info!("Setting up server");
|
|
||||||
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind random port");
|
|
||||||
let port = listener.local_addr().unwrap().port();
|
|
||||||
|
|
||||||
let server = contextswitch_api::run(listener, settings).expect("Failed to bind address");
|
|
||||||
let _ = tokio::spawn(server);
|
|
||||||
format!("http://127.0.0.1:{}", port)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn setup_taskwarrior(mut settings: Settings) -> String {
|
|
||||||
info!("Setting up Taskwarrior");
|
|
||||||
let tmp_dir = Temp::new_dir().unwrap();
|
|
||||||
settings.taskwarrior.data_location = tmp_dir.to_str().map(String::from);
|
|
||||||
let task_data_location = taskwarrior::load_config(&settings.taskwarrior);
|
|
||||||
tmp_dir.release();
|
|
||||||
|
|
||||||
task_data_location
|
|
||||||
}
|
|
||||||
|
|
||||||
#[fixture]
|
|
||||||
#[once]
|
|
||||||
pub fn app_address() -> String {
|
|
||||||
let settings = Settings::new_from_file(Some("config/test".to_string()))
|
|
||||||
.expect("Cannot load test configuration");
|
|
||||||
setup_tracing(&settings);
|
|
||||||
let address = setup_server(&settings);
|
|
||||||
setup_taskwarrior(settings);
|
|
||||||
address
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
mod health_check;
|
|
||||||
mod helpers;
|
|
||||||
mod tasks;
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
use crate::helpers::app_address;
|
|
||||||
use contextswitch::{Bookmark, ContextswitchData, NewTask, Task};
|
|
||||||
use contextswitch_api::contextswitch as cs;
|
|
||||||
use http::uri::Uri;
|
|
||||||
use rstest::*;
|
|
||||||
|
|
||||||
mod list_tasks {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[rstest]
|
|
||||||
#[tokio::test]
|
|
||||||
async fn list_tasks(app_address: &str) {
|
|
||||||
let task = cs::add_task(vec![
|
|
||||||
"test",
|
|
||||||
"list_tasks",
|
|
||||||
"contextswitch:'{\"bookmarks\":[{\"uri\":\"https://example.com/path?filter=1\"}]}'",
|
|
||||||
])
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let tasks: Vec<Task> = reqwest::Client::new()
|
|
||||||
.get(&format!("{}/tasks?filter={}", &app_address, task.id))
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.expect("Failed to execute request")
|
|
||||||
.json()
|
|
||||||
.await
|
|
||||||
.expect("Cannot parse JSON result");
|
|
||||||
|
|
||||||
assert_eq!(tasks.len(), 1);
|
|
||||||
assert_eq!(tasks[0].description, "test list_tasks");
|
|
||||||
let cs_data = tasks[0].contextswitch.as_ref().unwrap();
|
|
||||||
assert_eq!(cs_data.bookmarks.len(), 1);
|
|
||||||
assert_eq!(cs_data.bookmarks[0].content, None);
|
|
||||||
assert_eq!(
|
|
||||||
cs_data.bookmarks[0].uri,
|
|
||||||
"https://example.com/path?filter=1".parse::<Uri>().unwrap()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[rstest]
|
|
||||||
#[tokio::test]
|
|
||||||
async fn list_tasks_with_unknown_cs_data(app_address: &str) {
|
|
||||||
let task = cs::add_task(vec![
|
|
||||||
"test",
|
|
||||||
"list_tasks_with_unknown_cs_data",
|
|
||||||
"contextswitch:'{\"unknown\": 1}'",
|
|
||||||
])
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let tasks: Vec<Task> = reqwest::Client::new()
|
|
||||||
.get(&format!("{}/tasks?filter={}", &app_address, task.id))
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.expect("Failed to execute request")
|
|
||||||
.json()
|
|
||||||
.await
|
|
||||||
.expect("Cannot parse JSON result");
|
|
||||||
|
|
||||||
assert_eq!(tasks.len(), 1);
|
|
||||||
assert_eq!(tasks[0].description, "test list_tasks_with_unknown_cs_data");
|
|
||||||
assert!(tasks[0].contextswitch.is_none());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[rstest]
|
|
||||||
#[tokio::test]
|
|
||||||
async fn list_tasks_with_invalid_cs_data(app_address: &str) {
|
|
||||||
let task = cs::add_task(vec![
|
|
||||||
"test",
|
|
||||||
"list_tasks_with_invalid_contextswitch_data",
|
|
||||||
"contextswitch:'}'",
|
|
||||||
])
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let tasks: Vec<Task> = reqwest::Client::new()
|
|
||||||
.get(&format!("{}/tasks?filter={}", &app_address, task.id))
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.expect("Failed to execute request")
|
|
||||||
.json()
|
|
||||||
.await
|
|
||||||
.expect("Cannot parse JSON result");
|
|
||||||
|
|
||||||
assert_eq!(tasks.len(), 1);
|
|
||||||
assert_eq!(
|
|
||||||
tasks[0].description,
|
|
||||||
"test list_tasks_with_invalid_contextswitch_data"
|
|
||||||
);
|
|
||||||
assert!(tasks[0].contextswitch.is_none());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod add_task {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[rstest]
|
|
||||||
#[tokio::test]
|
|
||||||
async fn add_task(app_address: &str) {
|
|
||||||
let task: Task = reqwest::Client::new()
|
|
||||||
.post(&format!("{}/tasks", &app_address))
|
|
||||||
.json(&NewTask {
|
|
||||||
definition:
|
|
||||||
"test add_task contextswitch:{\"bookmarks\":[{\"uri\":\"https://example.com/path?filter=1\"}]}"
|
|
||||||
.to_string(),
|
|
||||||
})
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.expect("Failed to execute request")
|
|
||||||
.json()
|
|
||||||
.await
|
|
||||||
.expect("Cannot parse JSON result");
|
|
||||||
|
|
||||||
assert_eq!(task.description, "test add_task");
|
|
||||||
assert_eq!(
|
|
||||||
task.contextswitch.as_ref().unwrap(),
|
|
||||||
&ContextswitchData {
|
|
||||||
bookmarks: vec![Bookmark {
|
|
||||||
uri: "https://example.com/path?filter=1".parse::<Uri>().unwrap(),
|
|
||||||
content: None
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod update_task {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[rstest]
|
|
||||||
#[tokio::test]
|
|
||||||
async fn update_task(app_address: &str) {
|
|
||||||
let mut task = cs::add_task(vec![
|
|
||||||
"test",
|
|
||||||
"update_task",
|
|
||||||
"contextswitch:'{\"bookmarks\":[{\"uri\":\"https://example.com/path?filter=1\"}]}'",
|
|
||||||
])
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
task.description = "updated task description".to_string();
|
|
||||||
let cs_data = task.contextswitch.as_mut().unwrap();
|
|
||||||
cs_data.bookmarks.push(Bookmark {
|
|
||||||
uri: "https://example.com/path2".parse::<Uri>().unwrap(),
|
|
||||||
content: None,
|
|
||||||
});
|
|
||||||
|
|
||||||
let updated_task: Task = reqwest::Client::new()
|
|
||||||
.put(&format!("{}/tasks/{}", &app_address, task.id))
|
|
||||||
.json(&task)
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.expect("Failed to execute request")
|
|
||||||
.json()
|
|
||||||
.await
|
|
||||||
.expect("Cannot parse JSON result");
|
|
||||||
|
|
||||||
assert_eq!(updated_task.description, "updated task description");
|
|
||||||
assert_eq!(
|
|
||||||
updated_task.contextswitch.as_ref().unwrap(),
|
|
||||||
&ContextswitchData {
|
|
||||||
bookmarks: vec![
|
|
||||||
Bookmark {
|
|
||||||
uri: "https://example.com/path?filter=1".parse::<Uri>().unwrap(),
|
|
||||||
content: None
|
|
||||||
},
|
|
||||||
Bookmark {
|
|
||||||
uri: "https://example.com/path2".parse::<Uri>().unwrap(),
|
|
||||||
content: None
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO : test incoherent task id
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::contextswitch::taskwarrior;
|
use crate::contextswitch::taskwarrior;
|
||||||
use contextswitch::Task;
|
use contextswitch_types::Task;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
fn error_chain_fmt(
|
fn error_chain_fmt(
|
||||||
@@ -23,8 +23,12 @@ impl std::fmt::Debug for ContextswitchError {
|
|||||||
|
|
||||||
#[derive(thiserror::Error)]
|
#[derive(thiserror::Error)]
|
||||||
pub enum ContextswitchError {
|
pub enum ContextswitchError {
|
||||||
#[error("Invalid Contextswitch data")]
|
#[error("Invalid Contextswitch data: {data}")]
|
||||||
InvalidDataError(#[from] serde_json::Error),
|
InvalidDataError {
|
||||||
|
#[source]
|
||||||
|
source: serde_json::Error,
|
||||||
|
data: String,
|
||||||
|
},
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
UnexpectedError(#[from] anyhow::Error),
|
UnexpectedError(#[from] anyhow::Error),
|
||||||
}
|
}
|
||||||
@@ -44,13 +48,5 @@ pub async fn add_task(add_args: Vec<&str>) -> Result<Task, ContextswitchError> {
|
|||||||
let taskwarrior_task = taskwarrior::add_task(add_args)
|
let taskwarrior_task = taskwarrior::add_task(add_args)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| ContextswitchError::UnexpectedError(e.into()))?;
|
.map_err(|e| ContextswitchError::UnexpectedError(e.into()))?;
|
||||||
Ok(taskwarrior_task.into())
|
Ok((&taskwarrior_task).into())
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug")]
|
|
||||||
pub async fn update_task(task_to_update: Task) -> Result<Task, ContextswitchError> {
|
|
||||||
let taskwarrior_task = taskwarrior::update_task(task_to_update.try_into()?)
|
|
||||||
.await
|
|
||||||
.map_err(|e| ContextswitchError::UnexpectedError(e.into()))?;
|
|
||||||
Ok(taskwarrior_task.into())
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,262 @@
|
|||||||
|
use anyhow::{anyhow, Context};
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use configparser::ini::Ini;
|
||||||
|
use contextswitch_types::{ContextswitchData, Task, TaskId};
|
||||||
|
use regex::Regex;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json;
|
||||||
|
use std::env;
|
||||||
|
use std::fmt;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::process::Command;
|
||||||
|
use std::str;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
use tracing::{debug, warn};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
|
||||||
|
pub struct TaskwarriorTaskLocalId(pub u64);
|
||||||
|
|
||||||
|
impl fmt::Display for TaskwarriorTaskLocalId {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "{}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
|
||||||
|
pub struct TaskwarriorTaskId(pub Uuid);
|
||||||
|
|
||||||
|
impl fmt::Display for TaskwarriorTaskId {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "{}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&TaskwarriorTaskId> for TaskId {
|
||||||
|
fn from(task: &TaskwarriorTaskId) -> Self {
|
||||||
|
TaskId(task.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||||
|
pub struct TaskwarriorTask {
|
||||||
|
pub uuid: TaskwarriorTaskId,
|
||||||
|
pub id: TaskwarriorTaskLocalId,
|
||||||
|
#[serde(with = "contextswitch_types::tw_date_format")]
|
||||||
|
pub entry: DateTime<Utc>,
|
||||||
|
#[serde(with = "contextswitch_types::tw_date_format")]
|
||||||
|
pub modified: DateTime<Utc>,
|
||||||
|
pub status: contextswitch_types::Status,
|
||||||
|
pub description: String,
|
||||||
|
pub urgency: f64,
|
||||||
|
#[serde(
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
with = "contextswitch_types::opt_tw_date_format"
|
||||||
|
)]
|
||||||
|
pub due: Option<DateTime<Utc>>,
|
||||||
|
#[serde(
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
with = "contextswitch_types::opt_tw_date_format"
|
||||||
|
)]
|
||||||
|
pub start: Option<DateTime<Utc>>,
|
||||||
|
#[serde(
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
with = "contextswitch_types::opt_tw_date_format"
|
||||||
|
)]
|
||||||
|
pub end: Option<DateTime<Utc>>,
|
||||||
|
#[serde(
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
with = "contextswitch_types::opt_tw_date_format"
|
||||||
|
)]
|
||||||
|
pub wait: Option<DateTime<Utc>>,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub parent: Option<Uuid>,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub project: Option<String>,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub priority: Option<contextswitch_types::Priority>,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub recur: Option<contextswitch_types::Recurrence>,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub tags: Option<Vec<String>>,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub contextswitch: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&TaskwarriorTask> for Task {
|
||||||
|
fn from(task: &TaskwarriorTask) -> Self {
|
||||||
|
let cs_data =
|
||||||
|
task.contextswitch
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|cs_string| -> Option<ContextswitchData> {
|
||||||
|
let contextswitch_data_result = serde_json::from_str(cs_string);
|
||||||
|
if contextswitch_data_result.is_err() {
|
||||||
|
warn!(
|
||||||
|
"Invalid Contextswitch data found in {}: {}",
|
||||||
|
&task.uuid, cs_string
|
||||||
|
);
|
||||||
|
}
|
||||||
|
contextswitch_data_result.ok()
|
||||||
|
});
|
||||||
|
|
||||||
|
Task {
|
||||||
|
id: (&task.uuid).into(),
|
||||||
|
entry: task.entry,
|
||||||
|
modified: task.modified,
|
||||||
|
status: task.status,
|
||||||
|
description: task.description.clone(),
|
||||||
|
urgency: task.urgency,
|
||||||
|
due: task.due,
|
||||||
|
start: task.start,
|
||||||
|
end: task.end,
|
||||||
|
wait: task.wait,
|
||||||
|
parent: task.parent,
|
||||||
|
project: task.project.clone(),
|
||||||
|
priority: task.priority,
|
||||||
|
recur: task.recur,
|
||||||
|
tags: task.tags.clone(),
|
||||||
|
contextswitch: cs_data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
pub enum TaskwarriorError {
|
||||||
|
#[error("Error while executing Taskwarrior")]
|
||||||
|
ExecutionError(#[from] std::io::Error),
|
||||||
|
#[error("Error while parsing Taskwarrior output")]
|
||||||
|
OutputParsingError {
|
||||||
|
#[source]
|
||||||
|
source: serde_json::Error,
|
||||||
|
output: String,
|
||||||
|
},
|
||||||
|
#[error(transparent)]
|
||||||
|
UnexpectedError(#[from] anyhow::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_default_config(data_location: &str) -> String {
|
||||||
|
let mut taskrc = Ini::new();
|
||||||
|
taskrc.setstr("default", "data.location", Some(data_location));
|
||||||
|
taskrc.setstr("default", "uda.contextswitch.type", Some("string"));
|
||||||
|
taskrc.setstr(
|
||||||
|
"default",
|
||||||
|
"uda.contextswitch.label",
|
||||||
|
Some("Contextswitch data"),
|
||||||
|
);
|
||||||
|
taskrc.setstr("default", "uda.contextswitch.default", Some("{}"));
|
||||||
|
|
||||||
|
let taskrc_path = Path::new(&data_location).join(".taskrc");
|
||||||
|
let taskrc_location = taskrc_path.to_str().unwrap();
|
||||||
|
taskrc.write(taskrc_location).unwrap();
|
||||||
|
|
||||||
|
taskrc_location.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_config(task_data_location: Option<&str>) -> String {
|
||||||
|
if let Ok(taskrc_location) = env::var("TASKRC") {
|
||||||
|
let mut taskrc = Ini::new();
|
||||||
|
taskrc
|
||||||
|
.load(&taskrc_location)
|
||||||
|
.unwrap_or_else(|_| panic!("Cannot load taskrc file {}", taskrc_location));
|
||||||
|
let data_location = taskrc.get("default", "data.location").unwrap_or_else(|| {
|
||||||
|
panic!(
|
||||||
|
"'data.location' must be set in taskrc file {}",
|
||||||
|
taskrc_location
|
||||||
|
)
|
||||||
|
});
|
||||||
|
debug!(
|
||||||
|
"Extracted data location `{}` from existing taskrc `{}`",
|
||||||
|
data_location, taskrc_location
|
||||||
|
);
|
||||||
|
|
||||||
|
data_location
|
||||||
|
} else {
|
||||||
|
let data_location = task_data_location
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
env::var("TASK_DATA_LOCATION")
|
||||||
|
.expect("Expecting TASKRC or TASK_DATA_LOCATION environment variable value")
|
||||||
|
});
|
||||||
|
let taskrc_location = write_default_config(&data_location);
|
||||||
|
|
||||||
|
env::set_var("TASKRC", &taskrc_location);
|
||||||
|
debug!("Default taskrc written in `{}`", &taskrc_location);
|
||||||
|
|
||||||
|
data_location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug")]
|
||||||
|
pub fn list_tasks(filters: Vec<&str>) -> Result<Vec<TaskwarriorTask>, TaskwarriorError> {
|
||||||
|
let args = [filters, vec!["export"]].concat();
|
||||||
|
let export_output = Command::new("task")
|
||||||
|
.args(args)
|
||||||
|
.output()
|
||||||
|
.map_err(TaskwarriorError::ExecutionError)?;
|
||||||
|
|
||||||
|
let output =
|
||||||
|
String::from_utf8(export_output.stdout).context("Failed to read Taskwarrior output")?;
|
||||||
|
|
||||||
|
let tasks: Vec<TaskwarriorTask> = serde_json::from_str(&output)
|
||||||
|
.map_err(|e| TaskwarriorError::OutputParsingError { source: e, output })?;
|
||||||
|
|
||||||
|
Ok(tasks)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug")]
|
||||||
|
pub fn get_task_by_local_id(
|
||||||
|
id: &TaskwarriorTaskLocalId,
|
||||||
|
) -> Result<Option<TaskwarriorTask>, TaskwarriorError> {
|
||||||
|
let mut tasks: Vec<TaskwarriorTask> = list_tasks(vec![&id.to_string()])?;
|
||||||
|
if tasks.len() > 1 {
|
||||||
|
return Err(TaskwarriorError::UnexpectedError(anyhow!(
|
||||||
|
"Found more than 1 task when searching for task with local ID {}",
|
||||||
|
id
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(tasks.pop())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug")]
|
||||||
|
pub async fn add_task(add_args: Vec<&str>) -> Result<TaskwarriorTask, TaskwarriorError> {
|
||||||
|
lazy_static! {
|
||||||
|
static ref RE: Regex = Regex::new(r"Created task (?P<id>\d+).").unwrap();
|
||||||
|
static ref LOCK: Mutex<u32> = Mutex::new(0);
|
||||||
|
}
|
||||||
|
let _lock = LOCK.lock().await;
|
||||||
|
|
||||||
|
let mut args = vec!["add"];
|
||||||
|
args.extend(add_args);
|
||||||
|
let add_output = Command::new("task")
|
||||||
|
.args(args)
|
||||||
|
.output()
|
||||||
|
.map_err(TaskwarriorError::ExecutionError)?;
|
||||||
|
let output =
|
||||||
|
String::from_utf8(add_output.stdout).context("Failed to read Taskwarrior output")?;
|
||||||
|
let task_id_capture = RE
|
||||||
|
.captures(&output)
|
||||||
|
.ok_or_else(|| anyhow!("Cannot extract task ID from: {}", &output))?;
|
||||||
|
let task_id_str = task_id_capture
|
||||||
|
.name("id")
|
||||||
|
.ok_or_else(|| anyhow!("Cannot extract task ID value from: {}", &output))?
|
||||||
|
.as_str();
|
||||||
|
|
||||||
|
let task_id = TaskwarriorTaskLocalId(
|
||||||
|
task_id_str
|
||||||
|
.parse::<u64>()
|
||||||
|
.context("Cannot parse task ID value")?,
|
||||||
|
);
|
||||||
|
|
||||||
|
let task = get_task_by_local_id(&task_id)?;
|
||||||
|
task.ok_or_else(|| {
|
||||||
|
TaskwarriorError::UnexpectedError(anyhow!(
|
||||||
|
"Newly created task with ID {} was not found",
|
||||||
|
task_id
|
||||||
|
))
|
||||||
|
})
|
||||||
|
}
|
||||||
+43
-195
@@ -1,202 +1,50 @@
|
|||||||
use chrono::{DateTime, Utc};
|
use actix_web::{dev::Server, http, middleware, web, App, HttpServer};
|
||||||
use http::uri::Uri;
|
use listenfd::ListenFd;
|
||||||
use serde::{Deserialize, Serialize};
|
use std::env;
|
||||||
use std::fmt;
|
use std::net::TcpListener;
|
||||||
use uuid::Uuid;
|
use tracing_actix_web::TracingLogger;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy, Eq)]
|
#[macro_use]
|
||||||
#[serde(rename_all = "lowercase")]
|
extern crate lazy_static;
|
||||||
pub enum Recurrence {
|
|
||||||
Daily,
|
|
||||||
Weekly,
|
|
||||||
Monthly,
|
|
||||||
Yearly,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Recurrence {
|
pub mod contextswitch;
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
pub mod observability;
|
||||||
write!(f, "{}", format!("{:?}", self).to_lowercase())
|
pub mod routes;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy, Eq)]
|
pub fn run(listener: TcpListener) -> Result<Server, std::io::Error> {
|
||||||
#[serde(rename_all = "lowercase")]
|
let cs_front_base_url =
|
||||||
pub enum Status {
|
env::var("CS_FRONT_BASE_URL").unwrap_or_else(|_| "http://localhost:8080".to_string());
|
||||||
Pending,
|
let mut server = HttpServer::new(move || {
|
||||||
Completed,
|
App::new()
|
||||||
Recurring,
|
.wrap(TracingLogger::default())
|
||||||
Deleted,
|
.wrap(middleware::Compress::default())
|
||||||
}
|
.wrap(
|
||||||
|
middleware::DefaultHeaders::new()
|
||||||
|
.add(("Access-Control-Allow-Origin", cs_front_base_url.as_bytes()))
|
||||||
|
.add((
|
||||||
|
"Access-Control-Allow-Methods",
|
||||||
|
"POST, GET, OPTIONS".as_bytes(),
|
||||||
|
))
|
||||||
|
.add(("Access-Control-Allow-Headers", "content-type".as_bytes())),
|
||||||
|
)
|
||||||
|
.route("/ping", web::get().to(routes::ping))
|
||||||
|
.route("/tasks", web::get().to(routes::list_tasks))
|
||||||
|
.route("/tasks", web::post().to(routes::add_task))
|
||||||
|
.route(
|
||||||
|
"/tasks",
|
||||||
|
web::method(http::Method::OPTIONS).to(routes::option_task),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.keep_alive(60)
|
||||||
|
.shutdown_timeout(60);
|
||||||
|
|
||||||
impl fmt::Display for Status {
|
let mut listenfd = ListenFd::from_env();
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{}", format!("{:?}", self).to_lowercase())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy, Eq)]
|
server = if let Some(fdlistener) = listenfd.take_tcp_listener(0)? {
|
||||||
pub enum Priority {
|
server.listen(fdlistener)?
|
||||||
H,
|
} else {
|
||||||
M,
|
server.listen(listener)?
|
||||||
L,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Priority {
|
Ok(server.run())
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{:?}", self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
|
|
||||||
pub struct Bookmark {
|
|
||||||
#[serde(with = "uri")]
|
|
||||||
pub uri: Uri,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub content: Option<BookmarkContent>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
|
|
||||||
pub struct BookmarkContent {
|
|
||||||
pub title: String,
|
|
||||||
pub content_preview: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod uri {
|
|
||||||
use http::uri::Uri;
|
|
||||||
use serde::{self, Deserialize, Deserializer, Serializer};
|
|
||||||
|
|
||||||
pub fn serialize<S>(uri: &Uri, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
let uri_str = uri.to_string();
|
|
||||||
serializer.serialize_str(&uri_str)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Uri, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let s = String::deserialize(deserializer)?;
|
|
||||||
s.parse::<Uri>().map_err(serde::de::Error::custom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
|
|
||||||
pub struct ContextswitchData {
|
|
||||||
pub bookmarks: Vec<Bookmark>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
|
|
||||||
pub struct TaskId(pub Uuid);
|
|
||||||
|
|
||||||
impl fmt::Display for TaskId {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
|
|
||||||
pub struct Task {
|
|
||||||
pub id: TaskId,
|
|
||||||
#[serde(with = "tw_date_format")]
|
|
||||||
pub entry: DateTime<Utc>,
|
|
||||||
#[serde(with = "tw_date_format")]
|
|
||||||
pub modified: DateTime<Utc>,
|
|
||||||
pub status: Status,
|
|
||||||
pub description: String,
|
|
||||||
pub urgency: f64,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "opt_tw_date_format"
|
|
||||||
)]
|
|
||||||
pub due: Option<DateTime<Utc>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "opt_tw_date_format"
|
|
||||||
)]
|
|
||||||
pub start: Option<DateTime<Utc>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "opt_tw_date_format"
|
|
||||||
)]
|
|
||||||
pub end: Option<DateTime<Utc>>,
|
|
||||||
#[serde(
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none",
|
|
||||||
with = "opt_tw_date_format"
|
|
||||||
)]
|
|
||||||
pub wait: Option<DateTime<Utc>>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub parent: Option<TaskId>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub project: Option<String>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub priority: Option<Priority>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub recur: Option<Recurrence>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub tags: Option<Vec<String>>,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub contextswitch: Option<ContextswitchData>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
|
||||||
pub struct NewTask {
|
|
||||||
pub definition: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod tw_date_format {
|
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
|
||||||
use serde::{self, Deserialize, Deserializer, Serializer};
|
|
||||||
|
|
||||||
const FORMAT: &str = "%Y%m%dT%H%M%SZ";
|
|
||||||
|
|
||||||
pub fn serialize<S>(date: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
let s = format!("{}", date.format(FORMAT));
|
|
||||||
serializer.serialize_str(&s)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let s = String::deserialize(deserializer)?;
|
|
||||||
Utc.datetime_from_str(&s, FORMAT)
|
|
||||||
.map_err(serde::de::Error::custom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod opt_tw_date_format {
|
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
|
||||||
use serde::{self, Deserialize, Deserializer, Serializer};
|
|
||||||
|
|
||||||
const FORMAT: &str = "%Y%m%dT%H%M%SZ";
|
|
||||||
|
|
||||||
pub fn serialize<S>(date: &Option<DateTime<Utc>>, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
if let Some(ref d) = *date {
|
|
||||||
return serializer.serialize_str(&d.format(FORMAT).to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
serializer.serialize_none()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<DateTime<Utc>>, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let s = String::deserialize(deserializer)?;
|
|
||||||
Utc.datetime_from_str(&s, FORMAT)
|
|
||||||
.map(Some)
|
|
||||||
.map_err(serde::de::Error::custom)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
extern crate dotenv;
|
||||||
|
extern crate listenfd;
|
||||||
|
|
||||||
|
use contextswitch_api::observability::{get_subscriber, init_subscriber};
|
||||||
|
use contextswitch_api::{contextswitch::taskwarrior, run};
|
||||||
|
use dotenv::dotenv;
|
||||||
|
use std::env;
|
||||||
|
use std::net::TcpListener;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
let subscriber = get_subscriber("info".into());
|
||||||
|
init_subscriber(subscriber);
|
||||||
|
|
||||||
|
dotenv().ok();
|
||||||
|
|
||||||
|
let port = env::var("PORT").unwrap_or_else(|_| "8000".to_string());
|
||||||
|
taskwarrior::load_config(None);
|
||||||
|
|
||||||
|
let listener = TcpListener::bind(format!("0.0.0.0:{}", port)).expect("Failed to bind port");
|
||||||
|
run(listener)?.await
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ use tracing_log::LogTracer;
|
|||||||
use tracing_subscriber::fmt::TestWriter;
|
use tracing_subscriber::fmt::TestWriter;
|
||||||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter};
|
use tracing_subscriber::{layer::SubscriberExt, EnvFilter};
|
||||||
|
|
||||||
pub fn get_subscriber(env_filter_str: &str) -> impl Subscriber + Send + Sync {
|
pub fn get_subscriber(env_filter_str: String) -> impl Subscriber + Send + Sync {
|
||||||
let formatting_layer = BunyanFormattingLayer::new("contextswitch-api".into(), TestWriter::new);
|
let formatting_layer = BunyanFormattingLayer::new("contextswitch-api".into(), TestWriter::new);
|
||||||
|
|
||||||
let env_filter =
|
let env_filter =
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
use crate::contextswitch;
|
||||||
|
use actix_web::{http::StatusCode, web, HttpResponse, ResponseError};
|
||||||
|
use anyhow::Context;
|
||||||
|
use contextswitch_types::{NewTask, Task};
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct TaskQuery {
|
||||||
|
filter: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ResponseError for contextswitch::ContextswitchError {
|
||||||
|
fn status_code(&self) -> StatusCode {
|
||||||
|
match self {
|
||||||
|
contextswitch::ContextswitchError::InvalidDataError { .. } => {
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR
|
||||||
|
}
|
||||||
|
contextswitch::ContextswitchError::UnexpectedError(_) => {
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug", skip_all, fields(filter = %task_query.filter.as_ref().unwrap_or(&"".to_string())))]
|
||||||
|
pub async fn list_tasks(
|
||||||
|
task_query: web::Query<TaskQuery>,
|
||||||
|
) -> Result<HttpResponse, contextswitch::ContextswitchError> {
|
||||||
|
let filter = task_query
|
||||||
|
.filter
|
||||||
|
.as_ref()
|
||||||
|
.map_or(vec![], |filter| filter.split(' ').collect());
|
||||||
|
let tasks: Vec<Task> = contextswitch::list_tasks(filter)?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok()
|
||||||
|
.content_type("application/json")
|
||||||
|
.body(serde_json::to_string(&tasks).context("Cannot serialize Contextswitch task")?))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug", skip_all, fields(definition = %task.definition))]
|
||||||
|
pub async fn add_task(
|
||||||
|
task: web::Json<NewTask>,
|
||||||
|
) -> Result<HttpResponse, contextswitch::ContextswitchError> {
|
||||||
|
let task: Task = contextswitch::add_task(task.definition.split(' ').collect()).await?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok()
|
||||||
|
.content_type("application/json")
|
||||||
|
.body(serde_json::to_string(&task).context("Cannot serialize Contextswitch task")?))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug")]
|
||||||
|
pub fn option_task() -> HttpResponse {
|
||||||
|
HttpResponse::Ok().finish()
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::helpers::app_address;
|
pub mod test_helper;
|
||||||
use rstest::*;
|
use rstest::*;
|
||||||
|
use test_helper::app_address;
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
+128
@@ -0,0 +1,128 @@
|
|||||||
|
pub mod test_helper;
|
||||||
|
|
||||||
|
use contextswitch_api::contextswitch;
|
||||||
|
use contextswitch_types::{Bookmark, ContextswitchData, NewTask, Task, TaskId};
|
||||||
|
use http::uri::Uri;
|
||||||
|
use rstest::*;
|
||||||
|
use test_helper::app_address;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn list_tasks(app_address: &str) {
|
||||||
|
let task = contextswitch::add_task(vec![
|
||||||
|
"test",
|
||||||
|
"list_tasks",
|
||||||
|
"contextswitch:'{\"bookmarks\":[{\"uri\":\"https://example.com/path?filter=1\"}]}'",
|
||||||
|
])
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let tasks: Vec<Task> = reqwest::Client::new()
|
||||||
|
.get(&format!("{}/tasks?filter={}", &app_address, task.id))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request")
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.expect("Cannot parse JSON result");
|
||||||
|
|
||||||
|
assert_eq!(tasks.len(), 1);
|
||||||
|
assert_eq!(tasks[0].description, "test list_tasks");
|
||||||
|
let cs_data = tasks[0].contextswitch.as_ref().unwrap();
|
||||||
|
assert_eq!(cs_data.bookmarks.len(), 1);
|
||||||
|
assert_eq!(cs_data.bookmarks[0].content, None);
|
||||||
|
assert_eq!(
|
||||||
|
cs_data.bookmarks[0].uri,
|
||||||
|
"https://example.com/path?filter=1".parse::<Uri>().unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn list_tasks_with_unknown_contextswitch_data(app_address: &str) {
|
||||||
|
let task = contextswitch::add_task(vec![
|
||||||
|
"test",
|
||||||
|
"list_tasks_with_unknown_contextswitch_data",
|
||||||
|
"contextswitch:'{\"unknown\": 1}'",
|
||||||
|
])
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let tasks: Vec<Task> = reqwest::Client::new()
|
||||||
|
.get(&format!("{}/tasks?filter={}", &app_address, task.id))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request")
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.expect("Cannot parse JSON result");
|
||||||
|
|
||||||
|
assert_eq!(tasks.len(), 1);
|
||||||
|
assert_eq!(
|
||||||
|
tasks[0].description,
|
||||||
|
"test list_tasks_with_unknown_contextswitch_data"
|
||||||
|
);
|
||||||
|
assert!(tasks[0].contextswitch.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn list_tasks_with_invalid_contextswitch_data(app_address: &str) {
|
||||||
|
let task = contextswitch::add_task(vec![
|
||||||
|
"test",
|
||||||
|
"list_tasks_with_invalid_contextswitch_data",
|
||||||
|
"contextswitch:'}'",
|
||||||
|
])
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let tasks: Vec<Task> = reqwest::Client::new()
|
||||||
|
.get(&format!("{}/tasks?filter={}", &app_address, task.id))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request")
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.expect("Cannot parse JSON result");
|
||||||
|
|
||||||
|
assert_eq!(tasks.len(), 1);
|
||||||
|
assert_eq!(
|
||||||
|
tasks[0].description,
|
||||||
|
"test list_tasks_with_invalid_contextswitch_data"
|
||||||
|
);
|
||||||
|
assert!(tasks[0].contextswitch.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn add_task(app_address: &str) {
|
||||||
|
let response: serde_json::Value = reqwest::Client::new()
|
||||||
|
.post(&format!("{}/tasks", &app_address))
|
||||||
|
.json(&NewTask {
|
||||||
|
definition:
|
||||||
|
"test add_task contextswitch:{\"bookmarks\":[{\"uri\":\"https://example.com/path?filter=1\"}]}"
|
||||||
|
.to_string(),
|
||||||
|
})
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request")
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.expect("Cannot parse JSON result");
|
||||||
|
let new_task_id = TaskId(Uuid::parse_str(response["id"].as_str().unwrap()).unwrap());
|
||||||
|
let tasks = contextswitch::list_tasks(vec![&new_task_id.to_string()]).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(tasks.len(), 1);
|
||||||
|
assert_eq!(tasks[0].id, new_task_id);
|
||||||
|
assert_eq!(tasks[0].description, "test add_task");
|
||||||
|
assert_eq!(
|
||||||
|
tasks[0].contextswitch.as_ref().unwrap(),
|
||||||
|
&ContextswitchData {
|
||||||
|
bookmarks: vec![Bookmark {
|
||||||
|
uri: "https://example.com/path?filter=1".parse::<Uri>().unwrap(),
|
||||||
|
content: None
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
use contextswitch_api::contextswitch::taskwarrior;
|
||||||
|
use contextswitch_api::observability::{get_subscriber, init_subscriber};
|
||||||
|
use mktemp::Temp;
|
||||||
|
use rstest::*;
|
||||||
|
use std::fs;
|
||||||
|
use std::net::TcpListener;
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
|
fn setup_tracing() {
|
||||||
|
info!("Setting up tracing");
|
||||||
|
let subscriber = get_subscriber("debug".to_string());
|
||||||
|
init_subscriber(subscriber);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_server() -> String {
|
||||||
|
info!("Setting up server");
|
||||||
|
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind random port");
|
||||||
|
let port = listener.local_addr().unwrap().port();
|
||||||
|
|
||||||
|
let server = contextswitch_api::run(listener).expect("Failed to bind address");
|
||||||
|
let _ = tokio::spawn(server);
|
||||||
|
format!("http://127.0.0.1:{}", port)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_taskwarrior() -> String {
|
||||||
|
info!("Setting up TW");
|
||||||
|
let tmp_dir = Temp::new_dir().unwrap();
|
||||||
|
let task_data_location = taskwarrior::load_config(tmp_dir.to_str());
|
||||||
|
tmp_dir.release();
|
||||||
|
|
||||||
|
task_data_location
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_tasks(task_data_location: String) {
|
||||||
|
fs::remove_dir_all(task_data_location).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[fixture]
|
||||||
|
#[once]
|
||||||
|
pub fn app_address() -> String {
|
||||||
|
setup_tracing();
|
||||||
|
setup_taskwarrior();
|
||||||
|
setup_server()
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "contextswitch-web"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
authors = ["David Rousselie <david@rousselie.name>"]
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
path = "src/main.rs"
|
|
||||||
name = "contextswitch-web"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
contextswitch = { path = ".." }
|
|
||||||
yew = "0.19"
|
|
||||||
reqwasm = "0.5"
|
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
|
||||||
wasm-bindgen-futures = "0.4"
|
|
||||||
uikit-rs = { git = "https://github.com/dax/uikit-rs.git" }
|
|
||||||
wasm-bindgen = "0.2.79"
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
extend = "../Makefile.toml"
|
|
||||||
|
|
||||||
[tasks.build-release]
|
|
||||||
install_crate = { crate_name = "trunk", binary = "trunk" }
|
|
||||||
command = "trunk"
|
|
||||||
args = ["build", "--release"]
|
|
||||||
|
|
||||||
[tasks.run]
|
|
||||||
clear = true
|
|
||||||
install_crate = { crate_name = "trunk", binary = "trunk" }
|
|
||||||
command = "trunk"
|
|
||||||
args = ["serve"]
|
|
||||||
Vendored
-1
File diff suppressed because one or more lines are too long
@@ -1,13 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<title>Contextswitch</title>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<link rel="stylesheet" href="css/uikit.min.css" />
|
|
||||||
<script src="js/uikit.min.js"></script>
|
|
||||||
<script src="js/uikit-icons.min.js"></script>
|
|
||||||
<link data-trunk rel="copy-dir" href="css" />
|
|
||||||
<link data-trunk rel="copy-dir" href="js" />
|
|
||||||
</head>
|
|
||||||
</html>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export function get_api_base_url() {
|
|
||||||
return "http://localhost:8000/api";
|
|
||||||
}
|
|
||||||
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
@@ -1,2 +0,0 @@
|
|||||||
pub mod task;
|
|
||||||
pub mod tasks_list;
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
use contextswitch;
|
|
||||||
use uikit_rs as uk;
|
|
||||||
use yew::{classes, function_component, html, Callback, Classes, Html, MouseEvent, Properties};
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct TaskProps {
|
|
||||||
pub task: contextswitch::Task,
|
|
||||||
#[prop_or_default]
|
|
||||||
pub selected: bool,
|
|
||||||
#[prop_or_default]
|
|
||||||
pub on_task_select: Callback<Option<contextswitch::Task>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(Task)]
|
|
||||||
pub fn task(
|
|
||||||
TaskProps {
|
|
||||||
task,
|
|
||||||
selected,
|
|
||||||
on_task_select,
|
|
||||||
}: &TaskProps,
|
|
||||||
) -> Html {
|
|
||||||
let toggle_details = {
|
|
||||||
let task = task.clone();
|
|
||||||
let on_task_select = on_task_select.clone();
|
|
||||||
let is_task_selected = *selected;
|
|
||||||
Callback::from(move |_| {
|
|
||||||
on_task_select.emit(if is_task_selected {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(task.clone())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
let text_style = if task.status == contextswitch::Status::Completed {
|
|
||||||
uk::Text::Success
|
|
||||||
} else {
|
|
||||||
uk::Text::Emphasis
|
|
||||||
};
|
|
||||||
let arrow = if *selected {
|
|
||||||
uk::IconType::TriangleDown
|
|
||||||
} else {
|
|
||||||
uk::IconType::TriangleRight
|
|
||||||
};
|
|
||||||
|
|
||||||
let task_status_class: Classes = format!("task-status-{}", task.status).into();
|
|
||||||
let bookmark_count = if let Some(contextswitch) = &task.contextswitch {
|
|
||||||
contextswitch.bookmarks.len()
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
html! {
|
|
||||||
<uk::Card size={uk::CardSize::Small}
|
|
||||||
style={uk::CardStyle::Default}
|
|
||||||
hover={true}
|
|
||||||
width={uk::Width::_1_1}
|
|
||||||
class={task_status_class}>
|
|
||||||
<uk::CardBody padding={vec![uk::Padding::RemoveVertical]}
|
|
||||||
margin={vec![uk::Margin::SmallTop, uk::Margin::SmallBottom]}>
|
|
||||||
<uk::Grid gap_size={uk::GridGapSize::Small}
|
|
||||||
vertical_alignement={uk::FlexVerticalAlignement::Middle}>
|
|
||||||
<uk::Icon icon_type={uk::IconType::Check}
|
|
||||||
text_style={vec![text_style]} />
|
|
||||||
<TaskDescription task={task.clone()}
|
|
||||||
onclick={toggle_details.clone()} />
|
|
||||||
<uk::IconNav>
|
|
||||||
<li>
|
|
||||||
<uk::Icon icon_type={uk::IconType::FileEdit} href="#" />
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<uk::Link href="#" onclick={toggle_details.clone()}>
|
|
||||||
<uk::Icon icon_type={uk::IconType::Bookmark} />
|
|
||||||
<span> {bookmark_count}</span>
|
|
||||||
</uk::Link>
|
|
||||||
</li>
|
|
||||||
</uk::IconNav>
|
|
||||||
<uk::Icon icon_type={arrow} href="#" onclick={toggle_details} />
|
|
||||||
</uk::Grid>
|
|
||||||
{
|
|
||||||
if *selected {
|
|
||||||
html! {
|
|
||||||
<TaskDetails task={task.clone()} />
|
|
||||||
}
|
|
||||||
} else { html! {} }
|
|
||||||
}
|
|
||||||
</uk::CardBody>
|
|
||||||
</uk::Card>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct TaskDescriptionProps {
|
|
||||||
pub task: contextswitch::Task,
|
|
||||||
#[prop_or_default]
|
|
||||||
pub onclick: Callback<MouseEvent>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(TaskDescription)]
|
|
||||||
pub fn task_description(TaskDescriptionProps { task, onclick }: &TaskDescriptionProps) -> Html {
|
|
||||||
html! {
|
|
||||||
<uk::Flex width={uk::Width::_Expand} onclick={onclick}>
|
|
||||||
<uk::CardTitle text_style={vec![uk::Text::Lighter]}>
|
|
||||||
{task.description.clone()}
|
|
||||||
</uk::CardTitle>
|
|
||||||
</uk::Flex>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct TaskDetailsProps {
|
|
||||||
pub task: contextswitch::Task,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(TaskDetails)]
|
|
||||||
pub fn task_details(TaskDetailsProps { task }: &TaskDetailsProps) -> Html {
|
|
||||||
let priority = task
|
|
||||||
.priority
|
|
||||||
.as_ref()
|
|
||||||
.map(|prio| prio.to_string())
|
|
||||||
.unwrap_or_else(|| "-".to_string());
|
|
||||||
let project = task
|
|
||||||
.project
|
|
||||||
.as_ref()
|
|
||||||
.map(|proj| proj.to_string())
|
|
||||||
.unwrap_or_else(|| "-".to_string());
|
|
||||||
|
|
||||||
html! {
|
|
||||||
<div class={classes!(uk::Margin::Small)}>
|
|
||||||
<uk::Divider margin={vec![uk::Margin::Small]} />
|
|
||||||
{
|
|
||||||
if let Some(contextswitch) = &task.contextswitch {
|
|
||||||
html! {
|
|
||||||
<TaskContextswitch contextswitch={contextswitch.clone()} />
|
|
||||||
}
|
|
||||||
} else { html! {} }
|
|
||||||
}
|
|
||||||
<uk::Grid gap_size={uk::GridGapSize::Small}
|
|
||||||
child_width={uk::ChildWidth::_Expand}>
|
|
||||||
<span class={classes!(uk::Text::Meta)}>
|
|
||||||
{ format!("priority: {}", priority) }
|
|
||||||
</span>
|
|
||||||
<span class={classes!(uk::Text::Meta)}>
|
|
||||||
{ format!("project: {}", project) }
|
|
||||||
</span>
|
|
||||||
</uk::Grid>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct TaskContextswitchProps {
|
|
||||||
pub contextswitch: contextswitch::ContextswitchData,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(TaskContextswitch)]
|
|
||||||
pub fn task_contextswitch(
|
|
||||||
TaskContextswitchProps { contextswitch }: &TaskContextswitchProps,
|
|
||||||
) -> Html {
|
|
||||||
html! {
|
|
||||||
<uk::Grid gap_size={uk::GridGapSize::Small} height_match={true}>
|
|
||||||
{
|
|
||||||
contextswitch.bookmarks.iter().map(|bookmark| {
|
|
||||||
html! {
|
|
||||||
<TaskBookmark bookmark={bookmark.clone()} />
|
|
||||||
}
|
|
||||||
}).collect::<Html>()
|
|
||||||
}
|
|
||||||
<uk::Icon icon_type={uk::IconType::Plus}
|
|
||||||
margin={vec![uk::Margin::Remove]} />
|
|
||||||
</uk::Grid>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct TaskBookmarkProps {
|
|
||||||
pub bookmark: contextswitch::Bookmark,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(TaskBookmark)]
|
|
||||||
pub fn task_bookmark(TaskBookmarkProps { bookmark }: &TaskBookmarkProps) -> Html {
|
|
||||||
html! {
|
|
||||||
<div class={classes!(uk::Width::_1_1, uk::Text::Small, uk::Margin::Remove)}>
|
|
||||||
<uk::Grid gap_size={uk::GridGapSize::Small} vertical_alignement={uk::FlexVerticalAlignement::Middle}>
|
|
||||||
<uk::Icon icon_type={uk::IconType::Bookmark} />
|
|
||||||
<uk::Link href={bookmark.uri.to_string()}>{bookmark.uri.to_string()}</uk::Link>
|
|
||||||
</uk::Grid>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
use crate::components::task;
|
|
||||||
use contextswitch::Task;
|
|
||||||
use yew::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Properties, PartialEq)]
|
|
||||||
pub struct TasksListProps {
|
|
||||||
#[prop_or_default]
|
|
||||||
pub tasks: Vec<Task>,
|
|
||||||
#[prop_or_default]
|
|
||||||
pub selected_task: Option<Task>,
|
|
||||||
#[prop_or_default]
|
|
||||||
pub on_task_select: Callback<Option<Task>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(TasksList)]
|
|
||||||
pub fn tasks_list(
|
|
||||||
TasksListProps {
|
|
||||||
tasks,
|
|
||||||
selected_task,
|
|
||||||
on_task_select,
|
|
||||||
}: &TasksListProps,
|
|
||||||
) -> Html {
|
|
||||||
tasks
|
|
||||||
.iter()
|
|
||||||
.map(|task| {
|
|
||||||
let task_is_selected = selected_task
|
|
||||||
.clone()
|
|
||||||
.map(|t| t.id == task.id)
|
|
||||||
.unwrap_or(false);
|
|
||||||
|
|
||||||
html! {
|
|
||||||
<task::Task selected={task_is_selected}
|
|
||||||
on_task_select={on_task_select}
|
|
||||||
task={task.clone()} />
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
use components::tasks_list::TasksList;
|
|
||||||
use contextswitch::Task;
|
|
||||||
use reqwasm::http::Request;
|
|
||||||
use uikit_rs as uk;
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
use yew::prelude::*;
|
|
||||||
|
|
||||||
mod components;
|
|
||||||
|
|
||||||
#[wasm_bindgen(module = "/js/api.js")]
|
|
||||||
extern "C" {
|
|
||||||
fn get_api_base_url() -> String;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[function_component(App)]
|
|
||||||
pub fn app() -> Html {
|
|
||||||
let tasks = use_state(Vec::new);
|
|
||||||
{
|
|
||||||
let tasks = tasks.clone();
|
|
||||||
use_effect_with_deps(
|
|
||||||
move |_| {
|
|
||||||
wasm_bindgen_futures::spawn_local(async move {
|
|
||||||
let fetched_tasks: Vec<Task> =
|
|
||||||
Request::get(&format!("{}/tasks?filter=task", get_api_base_url()))
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.unwrap() // TODO
|
|
||||||
.json()
|
|
||||||
.await
|
|
||||||
.unwrap(); // TODO
|
|
||||||
tasks.set(fetched_tasks);
|
|
||||||
});
|
|
||||||
|| ()
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let selected_task = use_state(|| None);
|
|
||||||
let on_task_select = {
|
|
||||||
let selected_task = selected_task.clone();
|
|
||||||
Callback::from(move |task: Option<Task>| {
|
|
||||||
selected_task.set(task);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
html! {
|
|
||||||
<uk::Section style={uk::SectionStyle::Default}>
|
|
||||||
<uk::Container size={uk::ContainerSize::Small}>
|
|
||||||
<uk::Filter target=".status-filter"
|
|
||||||
filter_width={uk::Width::_Expand}
|
|
||||||
filter_component={uk::UIKitComponent::SubNav}
|
|
||||||
filter_class={"uk-subnav-pill"}
|
|
||||||
filters={vec![uk::FilterData { class: "".to_string(), label: "all".to_string() },
|
|
||||||
uk::FilterData { class: ".task-status-pending".to_string(), label: "pending".to_string() },
|
|
||||||
uk::FilterData { class: ".task-status-completed".to_string(), label: "completed".to_string() }]}>
|
|
||||||
<uk::Grid gap_size={uk::GridGapSize::Small}
|
|
||||||
margin={vec![uk::Margin::Default]}
|
|
||||||
height_match={true}
|
|
||||||
class={"status-filter"}>
|
|
||||||
<TasksList tasks={(*tasks).clone()}
|
|
||||||
selected_task={(*selected_task).clone()}
|
|
||||||
on_task_select={on_task_select} />
|
|
||||||
</uk::Grid>
|
|
||||||
</uk::Filter>
|
|
||||||
</uk::Container>
|
|
||||||
</uk::Section>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
use contextswitch_web::App;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
yew::start_app::<App>();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user