initial commit
21
counter_kand/DEPLOY.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
1. Auf github über Einstellungen ein Personal Access Token erstellen
|
||||||
|
1. Login mit `docker login ghcr.io`, github username als Username und das Token als Passwort eingeben
|
||||||
|
1. `docker build -t ghcr.io/<githubusername>/counter-frontend frontend` um das Frontend zu builden
|
||||||
|
1. `docker push ghcr.io/<githubusername>/counter-frontend` um das Frontend pushen
|
||||||
|
1. `docker build -t ghcr.io/<githubusername>/counter-backend backend` um das Backend zu builden
|
||||||
|
1. `docker push ghcr.io/<githubusername>/counter-backend` um das Backend zu pushen
|
||||||
|
1. Auf github die beiden Packages von «Private» auf «Public» stellen (oder ein pull-secret einrichten)
|
||||||
|
|
||||||
|
1. Deployment für das Backend mit dem Namen «counter-backend» und dem vorher erstellten image erstellen und folgende envs einrichten:
|
||||||
|
- DB_USER aus dem counter-database secret
|
||||||
|
- DB_NAME aus dem counter-database secret
|
||||||
|
- DB_PASSWORD aus dem counter-database secret
|
||||||
|
- DB_HOST aus dem counter-config configMap
|
||||||
|
- PASSPHRASE aus dem counter-secret secret
|
||||||
|
1. Service für das Backend mit dem Namen «counter-backend» erstellen und auf den Port 8080 mappen
|
||||||
|
1. Route für das Backend erstellen
|
||||||
|
|
||||||
|
1. Deployment für das Frontend mit dem Namen «counter-frontend» und dem vorher erstellten image erstellen und folgende envs einrichten:
|
||||||
|
- BACKEND_URL aus dem counter-config configMap
|
||||||
|
1. Service für das Frontend mit dem Namen «counter-frontend» erstellen und auf den Port 3000 mappen
|
||||||
|
1. Route für das Frontend erstellen
|
32
counter_kand/HOW_TO_FORK.md
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# How to copy the candidate repository
|
||||||
|
## Goal
|
||||||
|
This manual describes how a candidate of the module 109 can copy this repository into their personal work environment.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
To execute the following steps the following requirements must be met:
|
||||||
|
- Have a personal GitHub account
|
||||||
|
- Have the [git](https://git-scm.com/) application locally installed
|
||||||
|
- Have a sophisticated text editor (e.g. [vscode](https://code.visualstudio.com/)) locally installed
|
||||||
|
|
||||||
|
## Important git terminology
|
||||||
|
- Repository: the database, where all files and meta information are stored
|
||||||
|
- Working copy: a location, private to an individual, containing copies of files in use
|
||||||
|
- Checkout: process to retrieve a working copy of files from a repository
|
||||||
|
- Commit: store the current changes of the repository in a new commit along with a log message from the user describing the changes
|
||||||
|
- Update: bring the contents of a working copy inline with the repository
|
||||||
|
- Branching: working in an alternative thread of changes without interfering the current main branch
|
||||||
|
|
||||||
|
## Important git commands
|
||||||
|
- git clone: creating a private working copy of a remote repository
|
||||||
|
- git add: add changes to the commit area. All files in this area can now be versioned using the succeeding git commit command
|
||||||
|
- git commit: assign a commit message and therefore version all files within the staging area
|
||||||
|
- git status: check the current status of the repository. What files are in the commit area or modified
|
||||||
|
- git push: push local changes to the central remote repository
|
||||||
|
- git pull: pull remote changes to your local working copy
|
||||||
|
|
||||||
|
## How to copy (fork) the candidate repository into your personal GitHub profile
|
||||||
|
1) Open GitHub and login with your personal GitHub account
|
||||||
|
2) Open the candidate [repository](https://github.com/modul-i-ch-109/counter_kand) on GitHub
|
||||||
|
3) Within the repository use the option "fork" to create a copy of the current project within your personal GitHub profile ![fork_buttom](documentation/fork.png)
|
||||||
|
4) Select your personal GitHub profile as destination ![fork_destination](documentation/destination.png)
|
||||||
|
5) Now GitHub has copied the repository within your personal GitHub profile. This allows you to make changes independently of the original repository. If at a certain point you would like to copy back (merge) your changes back to the original project, you can use the merge request functionality within GitHub.
|
674
counter_kand/LICENSE
Normal file
@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is 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. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
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.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
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.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
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. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
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 Affero 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 special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU 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 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 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 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
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU 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 the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
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 GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
21
counter_kand/README.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Counting app - Demo React and NodeJS app
|
||||||
|
|
||||||
|
[![Publish counter docker image](https://github.com/modul-i-ch-109/counter/actions/workflows/action.yml/badge.svg?branch=master)](https://github.com/modul-i-ch-109/counter/actions/workflows/action.yml)
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
The goal was to create a dynamic counter app to replace the current paper-heavy counting tasks. The application must be able to run on the mobile and must be intuitive.
|
||||||
|
|
||||||
|
## Design
|
||||||
|
### Frontend
|
||||||
|
Using react in combination with the material design to create a intuitive UI.
|
||||||
|
|
||||||
|
![UseCaseView](documentation/usecaseView.PNG)
|
||||||
|
![ExecutionOfMeasurements](documentation/ExecutionOfMeasurementsView.PNG)
|
||||||
|
![MeasurementsView](documentation/measurementsView.PNG)
|
||||||
|
|
||||||
|
### Backend
|
||||||
|
|
||||||
|
Backend API is using node and postgres as persistent datastore.
|
||||||
|
# Development
|
||||||
|
Backend and frontend are combined in this project.
|
||||||
|
For the runtime the following env variable can control behavior of the application:
|
11
counter_kand/backend/.dockerignore
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# files not to be copied into the docker image
|
||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
Dockerfile*
|
||||||
|
docker-compose*
|
||||||
|
.dockerignore
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
README.md
|
||||||
|
LICENSE
|
||||||
|
.vscode
|
13
counter_kand/backend/.example-env
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Secrets are stored here.
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
NODE_ENV=development
|
||||||
|
|
||||||
|
# Database Information
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_NAME=database
|
||||||
|
DB_USER=postgres
|
||||||
|
DB_PASSWORD=password
|
||||||
|
|
||||||
|
# Test Secret
|
||||||
|
PASSPHRASE=secret
|
8
counter_kand/backend/.sequelizerc
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
'config': path.resolve('config', 'config.js'),
|
||||||
|
'models-path': path.resolve('src', 'models'),
|
||||||
|
'seeders-path': path.resolve('src', 'seeders'),
|
||||||
|
'migrations-path': path.resolve('src', 'migrations')
|
||||||
|
};
|
18
counter_kand/backend/Dockerfile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
FROM node:19-alpine
|
||||||
|
|
||||||
|
ENV npm_config_cache ./.npm-cache
|
||||||
|
RUN apk add --no-cache dos2unix
|
||||||
|
|
||||||
|
WORKDIR /srv/app
|
||||||
|
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN dos2unix entrypoints/*
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
ENTRYPOINT [ "entrypoints/production.sh" ]
|
||||||
|
CMD [ "npm", "start" ]
|
51
counter_kand/backend/README.md
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
# Backend
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
```
|
||||||
|
NODE_ENV=development
|
||||||
|
|
||||||
|
# Database Information
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_NAME=database
|
||||||
|
DB_USER=postgres
|
||||||
|
DB_PASSWORD=password
|
||||||
|
|
||||||
|
# Test Secret for /api/health/secret
|
||||||
|
PASSPHRASE=secret
|
||||||
|
```
|
||||||
|
|
||||||
|
## Available Scripts
|
||||||
|
|
||||||
|
### Migrations
|
||||||
|
|
||||||
|
The backend provides the following commands to initiate the database and run the migrations.
|
||||||
|
|
||||||
|
```
|
||||||
|
# create database
|
||||||
|
npx sequelize-cli db:create
|
||||||
|
|
||||||
|
# run migrations
|
||||||
|
npx sequelize-cli db:migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run the app
|
||||||
|
|
||||||
|
### Run the development environment
|
||||||
|
|
||||||
|
`npm run dev`
|
||||||
|
|
||||||
|
Runs the app in the development mode.
|
||||||
|
|
||||||
|
Open [http://localhost:8080](http://localhost:8080) to view the backend in the browser.
|
||||||
|
Open [http://localhost:3100](http://localhost:3100) to view the frontend in the browser.
|
||||||
|
|
||||||
|
The page will reload if you make edits. You will also see any lint errors in the console.
|
||||||
|
|
||||||
|
### Run the production environment
|
||||||
|
|
||||||
|
`npm start`
|
||||||
|
|
||||||
|
Runs the app in the production mode.
|
||||||
|
Open [http://localhost:8080](http://localhost:8080) to view the backend in the browser.
|
||||||
|
Open [http://localhost:3100](http://localhost:3100) to view the frontend in the browser.
|
28
counter_kand/backend/config/config.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
require('dotenv').config({ path: '.env' });
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
"development": {
|
||||||
|
"username": process.env.DB_USER || 'postgres',
|
||||||
|
"password": process.env.DB_PASSWORD || 'password',
|
||||||
|
"database": process.env.DB_NAME || 'database_development',
|
||||||
|
"host": process.env.DB_HOST || '127.0.0.1',
|
||||||
|
"dialect": "postgres",
|
||||||
|
"seederStorage": 'sequelize'
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"username": process.env.DB_USER || 'postgres',
|
||||||
|
"password": process.env.DB_PASSWORD || 'password',
|
||||||
|
"database": process.env.DB_NAME || 'database_test',
|
||||||
|
"host": process.env.DB_HOST || '127.0.0.1',
|
||||||
|
"dialect": "postgres",
|
||||||
|
"seederStorage": 'sequelize'
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"username": process.env.DB_USER || 'postgres',
|
||||||
|
"password": process.env.DB_PASSWORD || 'password',
|
||||||
|
"database": process.env.DB_NAME || 'database_production',
|
||||||
|
"host": process.env.DB_HOST || '127.0.0.1',
|
||||||
|
"dialect": "postgres"
|
||||||
|
},
|
||||||
|
"seederStorage": "sequelize"
|
||||||
|
}
|
13
counter_kand/backend/entrypoints/production.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
umask 0002
|
||||||
|
|
||||||
|
echo "WAITING FOR DATABASE DB_HOST = $DB_HOST"
|
||||||
|
./entrypoints/wait-for.sh $DB_HOST:5432
|
||||||
|
|
||||||
|
npx sequelize-cli db:create || true
|
||||||
|
npx sequelize-cli db:migrate --migrations-path src/migrations || true
|
||||||
|
npx sequelize-cli db:seed:all --seeders-path src/seeders || true
|
||||||
|
|
||||||
|
exec "$@"
|
191
counter_kand/backend/entrypoints/wait-for.sh
Executable file
@ -0,0 +1,191 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# The MIT License (MIT)
|
||||||
|
#
|
||||||
|
# Copyright (c) 2017 Eficode Oy
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in all
|
||||||
|
# copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
# SOFTWARE.
|
||||||
|
|
||||||
|
VERSION="2.2.3"
|
||||||
|
|
||||||
|
set -- "$@" -- "$TIMEOUT" "$QUIET" "$PROTOCOL" "$HOST" "$PORT" "$result"
|
||||||
|
TIMEOUT=15
|
||||||
|
QUIET=0
|
||||||
|
# The protocol to make the request with, either "tcp" or "http"
|
||||||
|
PROTOCOL="tcp"
|
||||||
|
|
||||||
|
echoerr() {
|
||||||
|
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
exitcode="$1"
|
||||||
|
cat << USAGE >&2
|
||||||
|
Usage:
|
||||||
|
$0 host:port|url [-t timeout] [-- command args]
|
||||||
|
-q | --quiet Do not output any status messages
|
||||||
|
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
|
||||||
|
-v | --version Show the version of this tool
|
||||||
|
-- COMMAND ARGS Execute command with args after the test finishes
|
||||||
|
USAGE
|
||||||
|
exit "$exitcode"
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for() {
|
||||||
|
case "$PROTOCOL" in
|
||||||
|
tcp)
|
||||||
|
if ! command -v nc >/dev/null; then
|
||||||
|
echoerr 'nc command is missing!'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
http)
|
||||||
|
if ! command -v wget >/dev/null; then
|
||||||
|
echoerr 'wget command is missing!'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
TIMEOUT_END=$(($(date +%s) + TIMEOUT))
|
||||||
|
|
||||||
|
while :; do
|
||||||
|
case "$PROTOCOL" in
|
||||||
|
tcp)
|
||||||
|
nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1
|
||||||
|
;;
|
||||||
|
http)
|
||||||
|
wget --timeout=1 -q "$HOST" -O /dev/null > /dev/null 2>&1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echoerr "Unknown protocol '$PROTOCOL'"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
result=$?
|
||||||
|
|
||||||
|
if [ $result -eq 0 ] ; then
|
||||||
|
if [ $# -gt 7 ] ; then
|
||||||
|
for result in $(seq $(($# - 7))); do
|
||||||
|
result=$1
|
||||||
|
shift
|
||||||
|
set -- "$@" "$result"
|
||||||
|
done
|
||||||
|
|
||||||
|
TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7
|
||||||
|
shift 7
|
||||||
|
exec "$@"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $TIMEOUT -ne 0 -a $(date +%s) -ge $TIMEOUT_END ]; then
|
||||||
|
echo "Operation timed out" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
while :; do
|
||||||
|
case "$1" in
|
||||||
|
http://*|https://*)
|
||||||
|
HOST="$1"
|
||||||
|
PROTOCOL="http"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
*:* )
|
||||||
|
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
|
||||||
|
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-v | --version)
|
||||||
|
echo $VERSION
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
-q | --quiet)
|
||||||
|
QUIET=1
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-q-*)
|
||||||
|
QUIET=0
|
||||||
|
echoerr "Unknown option: $1"
|
||||||
|
usage 1
|
||||||
|
;;
|
||||||
|
-q*)
|
||||||
|
QUIET=1
|
||||||
|
result=$1
|
||||||
|
shift 1
|
||||||
|
set -- -"${result#-q}" "$@"
|
||||||
|
;;
|
||||||
|
-t | --timeout)
|
||||||
|
TIMEOUT="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-t*)
|
||||||
|
TIMEOUT="${1#-t}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
--timeout=*)
|
||||||
|
TIMEOUT="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
--help)
|
||||||
|
usage 0
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
QUIET=0
|
||||||
|
echoerr "Unknown option: $1"
|
||||||
|
usage 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
QUIET=0
|
||||||
|
echoerr "Unknown argument: $1"
|
||||||
|
usage 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if ! [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then
|
||||||
|
echoerr "Error: invalid timeout '$TIMEOUT'"
|
||||||
|
usage 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$PROTOCOL" in
|
||||||
|
tcp)
|
||||||
|
if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then
|
||||||
|
echoerr "Error: you need to provide a host and port to test."
|
||||||
|
usage 2
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
http)
|
||||||
|
if [ "$HOST" = "" ]; then
|
||||||
|
echoerr "Error: you need to provide a host to test."
|
||||||
|
usage 2
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
wait_for "$@"
|
4116
counter_kand/backend/package-lock.json
generated
Normal file
49
counter_kand/backend/package.json
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"name": "trafficcounter",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": false,
|
||||||
|
"license": "GNU General Public License v3.0",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/modul-i-ch-109/counter"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"bcrypt": "^5.0.1",
|
||||||
|
"body-parse": "^0.1.0",
|
||||||
|
"config": "^3.3.7",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"dotenv": "^16.0.3",
|
||||||
|
"epilogue": "^0.7.1",
|
||||||
|
"express": "^4.18.1",
|
||||||
|
"nodemon": "^2.0.20",
|
||||||
|
"pg": "^8.7.3",
|
||||||
|
"postgres": "^3.3.1",
|
||||||
|
"sequelize": "^6.25.5",
|
||||||
|
"sequelize-cli": "^6.5.2",
|
||||||
|
"uuid": "^9.0.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"dev": "nodemon src/index.js",
|
||||||
|
"start": "node src/index.js",
|
||||||
|
"build": "",
|
||||||
|
"test": "jest",
|
||||||
|
"db_create": "sequelize db:create",
|
||||||
|
"migrate": "npx sequelize-cli db:migrate",
|
||||||
|
"seed": "npx sequelize-cli db:seed:all"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": "react-app"
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
31
counter_kand/backend/src/index.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
require('dotenv').config({ path: '.env' });
|
||||||
|
|
||||||
|
const port = process.env.SERVER_PORT || 8080;
|
||||||
|
const path = require('path');
|
||||||
|
const express = require('express');
|
||||||
|
const cors = require('cors');
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
|
const db = require('./models/index')
|
||||||
|
const usecaseApi = require('./routes/useCaseRoutes')
|
||||||
|
const measurementApi = require('./routes/measurementRoutes');
|
||||||
|
const healthApi = require('./routes/healthRoutes');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
app.use(cors());
|
||||||
|
app.use(bodyParser.json());
|
||||||
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
|
|
||||||
|
// serve static folder for production
|
||||||
|
let publicFolder = path.resolve(__dirname, '..')
|
||||||
|
publicFolder = path.resolve(publicFolder, '..')
|
||||||
|
app.use(express.static(path.join(publicFolder, 'build')));
|
||||||
|
|
||||||
|
// serve api
|
||||||
|
app.use('/api/useCases', usecaseApi)
|
||||||
|
app.use('/api/measurements', measurementApi)
|
||||||
|
app.use('/api/health', healthApi)
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`Listening on port ${port}`);
|
||||||
|
})
|
@ -0,0 +1,33 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = {
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
await queryInterface.createTable('UseCases', {
|
||||||
|
id: {
|
||||||
|
allowNull: false,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
type: Sequelize.INTEGER
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
measurementOptions: {
|
||||||
|
type: Sequelize.JSON
|
||||||
|
},
|
||||||
|
pinCode: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
allowNull: false,
|
||||||
|
type: Sequelize.DATE
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
allowNull: false,
|
||||||
|
type: Sequelize.DATE
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
await queryInterface.dropTable('UseCases');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,38 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
await queryInterface.createTable('Measurements', {
|
||||||
|
id: {
|
||||||
|
allowNull: false,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
type: Sequelize.INTEGER
|
||||||
|
},
|
||||||
|
groupName: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
timestamp: {
|
||||||
|
type: Sequelize.DATE
|
||||||
|
},
|
||||||
|
useCaseId: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
references: { model: 'UseCases', key: 'id' }
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
allowNull: false,
|
||||||
|
type: Sequelize.DATE
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
allowNull: false,
|
||||||
|
type: Sequelize.DATE
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
await queryInterface.dropTable('Measurements');
|
||||||
|
}
|
||||||
|
};
|
52
counter_kand/backend/src/models/index.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const Sequelize = require('sequelize');
|
||||||
|
const basename = path.basename(__filename);
|
||||||
|
const env = process.env.NODE_ENV || 'development';
|
||||||
|
const config = require(__dirname + '/../../config/config.js')[env];
|
||||||
|
const db = {};
|
||||||
|
let dbConf = {}
|
||||||
|
|
||||||
|
// reset the automatic date conversion of pg and work with the timezones
|
||||||
|
var pg = require('pg');
|
||||||
|
pg.types.setTypeParser(1082, 'text', function(text) {return text;});
|
||||||
|
pg.types.setTypeParser(1184, 'text', function(text) {return text;});
|
||||||
|
pg.types.setTypeParser(1114, 'text', function(text) {return text;});
|
||||||
|
|
||||||
|
dbConf.port = config.port;
|
||||||
|
dbConf.dialect = config.dialect
|
||||||
|
dbConf.host = config.host
|
||||||
|
dbConf.timezone = 'Europe/Vienna'
|
||||||
|
dbConf.dialectOptions = {
|
||||||
|
useUTC: false, //for reading from database
|
||||||
|
dateStrings: true,
|
||||||
|
typeCast: function (field, next) { // for reading from database
|
||||||
|
if (field.type === 'DATETIME') {
|
||||||
|
return field.string()
|
||||||
|
}
|
||||||
|
return next()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
let sequelize = new Sequelize(config.database, config.username, config.password, dbConf);
|
||||||
|
|
||||||
|
fs
|
||||||
|
.readdirSync(__dirname)
|
||||||
|
.filter(file => {
|
||||||
|
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
|
||||||
|
})
|
||||||
|
.forEach(file => {
|
||||||
|
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
|
||||||
|
db[model.name] = model;
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.keys(db).forEach(modelName => {
|
||||||
|
if (db[modelName].associate) {
|
||||||
|
db[modelName].associate(db);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
db.sequelize = sequelize;
|
||||||
|
db.Sequelize = Sequelize;
|
||||||
|
|
||||||
|
module.exports = db;
|
29
counter_kand/backend/src/models/measurement.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
'use strict';
|
||||||
|
const {
|
||||||
|
Model
|
||||||
|
} = require('sequelize');
|
||||||
|
|
||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
class Measurement extends Model {
|
||||||
|
/**
|
||||||
|
* Helper method for defining associations.
|
||||||
|
* This method is not a part of Sequelize lifecycle.
|
||||||
|
* The `models/index` file will call this method automatically.
|
||||||
|
*/
|
||||||
|
static associate(models) {
|
||||||
|
Measurement.belongsTo(models.UseCase, {
|
||||||
|
foreignKey: 'id'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Measurement.init({
|
||||||
|
groupName: DataTypes.STRING,
|
||||||
|
value: DataTypes.STRING,
|
||||||
|
timestamp: DataTypes.DATE,
|
||||||
|
}, {
|
||||||
|
sequelize,
|
||||||
|
modelName: 'Measurement',
|
||||||
|
});
|
||||||
|
|
||||||
|
return Measurement;
|
||||||
|
};
|
42
counter_kand/backend/src/models/usecase.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
'use strict';
|
||||||
|
const {
|
||||||
|
Model
|
||||||
|
} = require('sequelize');
|
||||||
|
|
||||||
|
const bcrypt = require('bcrypt')
|
||||||
|
|
||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
class UseCase extends Model {
|
||||||
|
/**
|
||||||
|
* Helper method for defining associations.
|
||||||
|
* This method is not a part of Sequelize lifecycle.
|
||||||
|
* The `models/index` file will call this method automatically.
|
||||||
|
*/
|
||||||
|
static associate(models) {
|
||||||
|
// define association here
|
||||||
|
UseCase.hasMany(models.Measurement, {
|
||||||
|
foreignKey: 'useCaseId'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UseCase.init({
|
||||||
|
name: DataTypes.STRING,
|
||||||
|
measurementOptions: DataTypes.JSON,
|
||||||
|
pinCode: DataTypes.STRING
|
||||||
|
}, {
|
||||||
|
sequelize,
|
||||||
|
modelName: 'UseCase',
|
||||||
|
});
|
||||||
|
|
||||||
|
// static class function to convert frontend numerical pin to hash
|
||||||
|
UseCase.generateHash = function(pinCode) {
|
||||||
|
return bcrypt.hashSync(pinCode, 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
// instance method to verify a numerical pin to the original hash
|
||||||
|
UseCase.prototype.validPinCode = function(pinCode) {
|
||||||
|
return bcrypt.compareSync(pinCode, this.pinCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return UseCase;
|
||||||
|
};
|
36
counter_kand/backend/src/routes/healthRoutes.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const db = require('../models/index')
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
// get method - health check - check if the database is connected
|
||||||
|
router.get('/database', (req, res, next) => {
|
||||||
|
db.Measurement.findAll()
|
||||||
|
.then(() => {
|
||||||
|
res.status(200).json({
|
||||||
|
message: 'OK: Database is connected',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: "NOK: Internal server error - database could NOT be connected. Details: " + err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// get method - secret check - check if secret can be read
|
||||||
|
router.get('/secret', (req, res, next) => {
|
||||||
|
const secret = process.env.PASSPHRASE || null
|
||||||
|
|
||||||
|
if(secret) {
|
||||||
|
res.status(200).json({
|
||||||
|
message: "OK: Secret can be read"
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
res.status(500).json({
|
||||||
|
error: "NOK: Secret could NOT be read"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router;
|
110
counter_kand/backend/src/routes/measurementRoutes.js
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
const db = require('../models/index')
|
||||||
|
|
||||||
|
// post method - creation of a new measurement
|
||||||
|
router.post('/', (req, res, next) => {
|
||||||
|
let measurement = {
|
||||||
|
groupName: req.body.groupName,
|
||||||
|
value: req.body.value,
|
||||||
|
timestamp: req.body.timestamp,
|
||||||
|
useCaseId: req.body.useCase
|
||||||
|
}
|
||||||
|
|
||||||
|
db.Measurement.create(measurement)
|
||||||
|
.then(result => {
|
||||||
|
res.status(200).json(result)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// get all measurement
|
||||||
|
router.get("/", (req, res, next) => {
|
||||||
|
db.Measurement.findAll()
|
||||||
|
.then(data => {
|
||||||
|
res.status(200).json(data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// get specific measurement by id
|
||||||
|
router.get("/:id", (req, res, next) => {
|
||||||
|
let measurementId = req.params.id
|
||||||
|
|
||||||
|
db.Measurement.findOne({ where:
|
||||||
|
{ 'id': measurementId }
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
res.status(200).json(data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// update measurement based on measurement id
|
||||||
|
router.put("/:id", (req, res, next) => {
|
||||||
|
let measurementId = req.params.id
|
||||||
|
let updatedMeasurement = {
|
||||||
|
groupName: req.body.groupName,
|
||||||
|
value: req.body.value,
|
||||||
|
timestamp: req.body.timestamp,
|
||||||
|
useCase: req.body.useCase
|
||||||
|
}
|
||||||
|
|
||||||
|
db.Measurement.findOne({ where:
|
||||||
|
{ 'id': measurementId }
|
||||||
|
})
|
||||||
|
.then(measurement => {
|
||||||
|
if(measurement) {
|
||||||
|
measurement.update(updatedMeasurement)
|
||||||
|
res.status(200).json(measurement)
|
||||||
|
} else {
|
||||||
|
res.status(404).json({
|
||||||
|
error: "Measurement with given id could not be found"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// delete measurement based on id
|
||||||
|
router.delete("/:id", (req, res, next) => {
|
||||||
|
let measurementId = req.params.id
|
||||||
|
|
||||||
|
db.Measurement.destroy({
|
||||||
|
where: { 'id': measurementId }
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
res.status(200).json({
|
||||||
|
data
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
202
counter_kand/backend/src/routes/useCaseRoutes.js
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const db = require('../models/index')
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
// post method - creation of a new usecase
|
||||||
|
router.post('/', (req, res, next) => {
|
||||||
|
let useCase = {
|
||||||
|
name: req.body.name,
|
||||||
|
measurementOptions: req.body.measurementOptions,
|
||||||
|
pinCode: db.UseCase.generateHash(req.body.pinCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
db.UseCase.create(useCase).then(result => {
|
||||||
|
res.status(200).json(result)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// get all use cases
|
||||||
|
router.get("/", (req, res, next) => {
|
||||||
|
db.UseCase.findAll()
|
||||||
|
.then(data => {
|
||||||
|
res.status(200).json(data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// get specific usecase by id
|
||||||
|
router.get("/:id", (req, res, next) => {
|
||||||
|
let useCaseId = req.params.id
|
||||||
|
|
||||||
|
db.UseCase.findOne({
|
||||||
|
where:
|
||||||
|
{ 'id': useCaseId }
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
res.status(200).json(data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// get measurements of a specific usecase
|
||||||
|
router.get("/:id/measurements", (req, res, next) => {
|
||||||
|
let useCaseId = req.params.id
|
||||||
|
|
||||||
|
db.UseCase.findOne({
|
||||||
|
where:
|
||||||
|
{ 'id': useCaseId },
|
||||||
|
include: [
|
||||||
|
{ model: db.Measurement, attributes: ["groupName", "value", "timestamp"] }
|
||||||
|
],
|
||||||
|
order: [
|
||||||
|
[db.Measurement, 'timestamp', 'DESC'],
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
res.status(200).json(data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// get measurements of a specific usecase
|
||||||
|
router.get("/:id/measurements/count", (req, res, next) => {
|
||||||
|
let useCaseId = req.params.id
|
||||||
|
|
||||||
|
db.UseCase.findOne({
|
||||||
|
where:
|
||||||
|
{ 'id': useCaseId },
|
||||||
|
include: [
|
||||||
|
{ model: db.Measurement, attributes: ["groupName", "value", "timestamp"] }
|
||||||
|
],
|
||||||
|
order: [
|
||||||
|
[db.Measurement, 'timestamp', 'DESC'],
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
let measurements = data.Measurements || []
|
||||||
|
res.status(200).json(measurements.length);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// verify if a given user provided the currect password
|
||||||
|
router.post("/:id/authorize", (req, res, next) => {
|
||||||
|
let useCaseId = req.params.id
|
||||||
|
let pinCode = req.body.pinCode
|
||||||
|
|
||||||
|
db.UseCase.findOne({
|
||||||
|
where:
|
||||||
|
{ 'id': useCaseId }
|
||||||
|
})
|
||||||
|
.then(useCase => {
|
||||||
|
if (useCase) {
|
||||||
|
if (useCase.validPinCode(pinCode)) {
|
||||||
|
res.status(200).json("Authenticated successfully")
|
||||||
|
} else {
|
||||||
|
res.status(401).json({
|
||||||
|
error: "Unauthorized access, wrong pin provided"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.status(404).json({
|
||||||
|
error: "Use case with given id could not be found"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// update usecase based on usecase id
|
||||||
|
router.put("/:id", (req, res, next) => {
|
||||||
|
let useCaseId = req.params.id
|
||||||
|
let updatedUseCase = {
|
||||||
|
name: req.body.name,
|
||||||
|
measurementOptions: req.body.measurementOptions,
|
||||||
|
}
|
||||||
|
|
||||||
|
db.UseCase.findOne({
|
||||||
|
where:
|
||||||
|
{ 'id': useCaseId }
|
||||||
|
})
|
||||||
|
.then(useCase => {
|
||||||
|
if (useCase) {
|
||||||
|
if (useCase.validPinCode(req.body.pinCode)) {
|
||||||
|
useCase.update(updatedUseCase)
|
||||||
|
res.status(200).json(useCase)
|
||||||
|
} else {
|
||||||
|
res.status(401).json({
|
||||||
|
error: "Unauthorized access, wrong pin provided"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.status(404).json({
|
||||||
|
error: "Use case with given id could not be found"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// delete usecase based on id
|
||||||
|
router.delete("/:id", (req, res, next) => {
|
||||||
|
let useCaseId = req.params.id
|
||||||
|
|
||||||
|
db.Measurement.destroy({
|
||||||
|
where:
|
||||||
|
{ 'useCaseId': useCaseId }
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
db.UseCase.destroy({
|
||||||
|
where: { 'id': useCaseId }
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
res.status(200).json({
|
||||||
|
data
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).json({
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
@ -0,0 +1,85 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const db = require('../models/index')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
await queryInterface.bulkInsert('UseCases', [{
|
||||||
|
name: 'Test Use Case',
|
||||||
|
measurementOptions: JSON.stringify([{
|
||||||
|
id: 0,
|
||||||
|
name: 'Test Measurement Option A',
|
||||||
|
options: [{
|
||||||
|
id: 0,
|
||||||
|
name: 'Test Measurement Option 1',
|
||||||
|
icon: 'arrow_back',
|
||||||
|
value: 1
|
||||||
|
}, {
|
||||||
|
id: 1,
|
||||||
|
name: 'Test Measurement Option 2',
|
||||||
|
icon: 'arrow_forward',
|
||||||
|
value: 2
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
|
||||||
|
name: 'Test Measurement Option B',
|
||||||
|
options: [{
|
||||||
|
id: 0,
|
||||||
|
name: 'Test Measurement Option 1',
|
||||||
|
icon: 'arrow_back',
|
||||||
|
value: 1
|
||||||
|
}, {
|
||||||
|
id: 1,
|
||||||
|
name: 'Test Measurement Option 2',
|
||||||
|
icon: 'arrow_forward',
|
||||||
|
value: 2
|
||||||
|
}]
|
||||||
|
}]),
|
||||||
|
pinCode: db.UseCase.generateHash('1234'),
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date()
|
||||||
|
}, {
|
||||||
|
name: 'Test Use Case 2',
|
||||||
|
measurementOptions: JSON.stringify([{
|
||||||
|
id: 0,
|
||||||
|
name: 'Test Measurement Option A',
|
||||||
|
options: [{
|
||||||
|
id: 0,
|
||||||
|
name: 'Test Measurement Option 1',
|
||||||
|
icon: 'arrow_back',
|
||||||
|
value: 1
|
||||||
|
}, {
|
||||||
|
id: 1,
|
||||||
|
name: 'Test Measurement Option 2',
|
||||||
|
icon: 'arrow_forward',
|
||||||
|
value: 2
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
|
||||||
|
name: 'Test Measurement Option B',
|
||||||
|
options: [{
|
||||||
|
id: 0,
|
||||||
|
name: 'Test Measurement Option 1',
|
||||||
|
icon: 'arrow_back',
|
||||||
|
value: 1
|
||||||
|
}, {
|
||||||
|
id: 1,
|
||||||
|
name: 'Test Measurement Option 2',
|
||||||
|
icon: 'arrow_forward',
|
||||||
|
value: 2
|
||||||
|
}]
|
||||||
|
}]),
|
||||||
|
pinCode: db.UseCase.generateHash('1234'),
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date()
|
||||||
|
}], {});
|
||||||
|
},
|
||||||
|
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
queryInterface.bulkDelete('UseCases', null, {});
|
||||||
|
}
|
||||||
|
};
|
47
counter_kand/docker-compose.yml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
version: '3.9'
|
||||||
|
|
||||||
|
services:
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: frontend
|
||||||
|
image: ghcr.io/modul-i-ch-109/counter_kand/counter_frontend:latest
|
||||||
|
ports:
|
||||||
|
- 3100:3100
|
||||||
|
- 3000:3000
|
||||||
|
environment:
|
||||||
|
BACKEND_URL: ${BACKEND_URL:-http://localhost:8080}
|
||||||
|
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: backend
|
||||||
|
image: ghcr.io/modul-i-ch-109/counter_kand/counter_backend:latest
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
environment:
|
||||||
|
NODE_ENV: production
|
||||||
|
DB_HOST: db
|
||||||
|
DB_NAME: counter
|
||||||
|
DB_USER: postgres
|
||||||
|
DB_PASSWORD: password
|
||||||
|
PASSPHRASE: secret
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:14
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: password
|
||||||
|
POSTGRES_DB: counter
|
||||||
|
|
||||||
|
pgadmin:
|
||||||
|
image: dpage/pgadmin4
|
||||||
|
ports:
|
||||||
|
- 8083:80
|
||||||
|
environment:
|
||||||
|
PGADMIN_DEFAULT_EMAIL: admin@admin.com
|
||||||
|
PGADMIN_DEFAULT_PASSWORD: root
|
||||||
|
depends_on:
|
||||||
|
- db
|
BIN
counter_kand/documentation/ExecutionOfMeasurementsView.PNG
Normal file
After Width: | Height: | Size: 71 KiB |
BIN
counter_kand/documentation/destination.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
counter_kand/documentation/fork.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
counter_kand/documentation/measurementsView.PNG
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
counter_kand/documentation/usecaseView.PNG
Normal file
After Width: | Height: | Size: 29 KiB |
10
counter_kand/frontend/.dockerignore
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
Dockerfile*
|
||||||
|
docker-compose*
|
||||||
|
.dockerignore
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
README.md
|
||||||
|
LICENSE
|
||||||
|
.vscode
|
13
counter_kand/frontend/.example-env
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Secrets are stored here.
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# React Dev Port
|
||||||
|
PORT=3100
|
||||||
|
GENERATE_SOURCEMAP=false #https://stackoverflow.com/questions/36051891/esri-failed-to-parse-source-map
|
||||||
|
|
||||||
|
BACKEND_URL=http://localhost:8080
|
||||||
|
|
||||||
|
# Further details regarding the build app
|
||||||
|
REACT_APP_VERSION=1.0.0
|
||||||
|
REACT_APP_NAME=$npm_package_name
|
23
counter_kand/frontend/Dockerfile
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
FROM node:19-alpine
|
||||||
|
|
||||||
|
ENV npm_config_cache ./.npm-cache
|
||||||
|
RUN apk add --no-cache dos2unix envsubst
|
||||||
|
|
||||||
|
WORKDIR /srv/app
|
||||||
|
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN dos2unix entrypoint.sh && \
|
||||||
|
npm run build && \
|
||||||
|
chown node: build/index.html && \
|
||||||
|
chgrp -R 0 /srv/app && \
|
||||||
|
chmod -R g=u /srv/app
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
ENTRYPOINT [ "./entrypoint.sh" ]
|
||||||
|
CMD ["npm", "run", "start"]
|
47
counter_kand/frontend/README.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Frontend
|
||||||
|
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
```
|
||||||
|
# React Dev Port
|
||||||
|
PORT=3000
|
||||||
|
REACT_APP_VERSION=1.0.0
|
||||||
|
REACT_APP_NAME=$npm_package_name
|
||||||
|
```
|
||||||
|
|
||||||
|
## Build Arguments
|
||||||
|
|
||||||
|
These variables need to be injected when creating a production build
|
||||||
|
|
||||||
|
```
|
||||||
|
REACT_APP_BACKEND_URL=http://localhost:8080
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run the app
|
||||||
|
|
||||||
|
### Run the development environment
|
||||||
|
|
||||||
|
`npm run dev`
|
||||||
|
|
||||||
|
Runs the app in the development mode.
|
||||||
|
|
||||||
|
Open [http://localhost:3000](http://localhost:3000) to view the frontend in the browser.
|
||||||
|
|
||||||
|
The page will reload if you make edits. You will also see any lint errors in the console.
|
||||||
|
|
||||||
|
### Run the production environment
|
||||||
|
|
||||||
|
`npm start`
|
||||||
|
|
||||||
|
Runs the app in the production mode.
|
||||||
|
|
||||||
|
Open [http://localhost:3100](http://localhost:3100) to view the frontend in the browser.
|
||||||
|
|
||||||
|
|
||||||
|
### `npm run build` - only available for frontend
|
||||||
|
|
||||||
|
Builds the app for production to the `build` folder.
|
||||||
|
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||||
|
|
||||||
|
The build is minified and the filenames include the hashes. Your app is ready to be deployed!
|
5
counter_kand/frontend/entrypoint.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -xe
|
||||||
|
|
||||||
|
echo "$(envsubst < build/index.html)" > build/index.html
|
||||||
|
exec "$@"
|
30868
counter_kand/frontend/package-lock.json
generated
Normal file
50
counter_kand/frontend/package.json
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"name": "trafficcounter",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": false,
|
||||||
|
"license": "GNU General Public License v3.0",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/modul-i-ch-109/counter"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@material-ui/icons": "^4.11.3",
|
||||||
|
"@testing-library/jest-dom": "^5.16.2",
|
||||||
|
"@testing-library/react": "^12.1.3",
|
||||||
|
"@testing-library/user-event": "^14.4.3",
|
||||||
|
"final-form": "^4.20.7",
|
||||||
|
"material-table": "^1.69.3",
|
||||||
|
"moment": "^2.29.1",
|
||||||
|
"react": "^17.0.2",
|
||||||
|
"react-dom": "^17.0.2",
|
||||||
|
"react-final-form": "^6.5.9",
|
||||||
|
"react-router-dom": "^6.4.3",
|
||||||
|
"react-scripts": "5.0.1",
|
||||||
|
"react-select": "^5.6.1",
|
||||||
|
"serve": "^14.1.1"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "npx serve -s build -l 3000",
|
||||||
|
"dev": "npx react-scripts start",
|
||||||
|
"build": "npx react-scripts build",
|
||||||
|
"test": "npx react-scripts test --watchAll=false",
|
||||||
|
"eject": "npx react-scripts eject",
|
||||||
|
"lint": "npx eslint --fix --ext .js,.ts,.tsx .",
|
||||||
|
"prettier": "npx prettier --ignore-path build --write \"**/*.+(js|json|ts|tsx)\""
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": "react-app"
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
BIN
counter_kand/frontend/public/favicon.png
Normal file
After Width: | Height: | Size: 9.0 KiB |
BIN
counter_kand/frontend/public/images/header.png
Normal file
After Width: | Height: | Size: 9.0 KiB |
51
counter_kand/frontend/public/index.html
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="icon" href="%PUBLIC_URL%/favicon.png" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta name="theme-color" content="#000000" />
|
||||||
|
<meta name="description" content="App for counting objects on a street" />
|
||||||
|
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||||
|
<!--
|
||||||
|
manifest.json provides metadata used when your web app is installed on a
|
||||||
|
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||||
|
-->
|
||||||
|
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||||
|
<!--
|
||||||
|
Notice the use of %PUBLIC_URL% in the tags above.
|
||||||
|
It will be replaced with the URL of the `public` folder during the build.
|
||||||
|
Only files inside the `public` folder can be referenced from the HTML.
|
||||||
|
|
||||||
|
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||||
|
work correctly both with client-side routing and a non-root public URL.
|
||||||
|
Learn how to configure a non-root public URL by running `npm run build`.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Include google font so that icons of Material Design are supported -->
|
||||||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
||||||
|
<script>
|
||||||
|
window.env = {
|
||||||
|
BACKEND_URL: '${BACKEND_URL}',
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<title>Counter</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
<!--
|
||||||
|
This HTML file is a template.
|
||||||
|
If you open it directly in the browser, you will see an empty page.
|
||||||
|
|
||||||
|
You can add webfonts, meta tags, or analytics to this file.
|
||||||
|
The build step will place the bundled scripts into the <body> tag.
|
||||||
|
|
||||||
|
To begin the development, run `npm start` or `yarn start`.
|
||||||
|
To create a production bundle, use `npm run build` or `yarn build`.
|
||||||
|
-->
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
15
counter_kand/frontend/public/manifest.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"short_name": "Counter",
|
||||||
|
"name": "Counter",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "favicon.ico",
|
||||||
|
"sizes": "64x64 32x32 24x24 16x16",
|
||||||
|
"type": "image/x-icon"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"start_url": ".",
|
||||||
|
"display": "standalone",
|
||||||
|
"theme_color": "#000000",
|
||||||
|
"background_color": "#ffffff"
|
||||||
|
}
|
3
counter_kand/frontend/public/robots.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# https://www.robotstxt.org/robotstxt.html
|
||||||
|
User-agent: *
|
||||||
|
Disallow:
|
42
counter_kand/frontend/src/components/App.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import React, { Fragment } from 'react';
|
||||||
|
import { Route, Routes } from 'react-router-dom';
|
||||||
|
import {
|
||||||
|
CssBaseline,
|
||||||
|
withStyles,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
|
||||||
|
import AppHeader from './appHeader';
|
||||||
|
import UseCaseManager from '../pages/useCaseManager';
|
||||||
|
import UseCaseMeasurement from '../pages/useCaseMeasurement';
|
||||||
|
import MeasurementView from '../pages/measurementView';
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
main: {
|
||||||
|
padding: theme.spacing(1),
|
||||||
|
[theme.breakpoints.down('xs')]: {
|
||||||
|
padding: theme.spacing(0.5),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const App = ({ classes }) => (
|
||||||
|
<Fragment>
|
||||||
|
<CssBaseline />
|
||||||
|
<AppHeader />
|
||||||
|
<main className={classes.main}>
|
||||||
|
<Routes>
|
||||||
|
<Route exact path="/" element={<UseCaseManager />} />
|
||||||
|
<Route path="useCases">
|
||||||
|
<Route exact path="" element={<UseCaseManager />} />
|
||||||
|
<Route exact path=":id" element={<UseCaseManager />} />
|
||||||
|
<Route exact path=":id/measurements">
|
||||||
|
<Route exact path="" element={<UseCaseMeasurement />} />
|
||||||
|
<Route exact path="view" element={<MeasurementView />} />
|
||||||
|
</Route>
|
||||||
|
</Route>
|
||||||
|
</Routes>
|
||||||
|
</main>
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default withStyles(styles)(App);
|
9
counter_kand/frontend/src/components/App.test.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from '@testing-library/react';
|
||||||
|
import App from './App';
|
||||||
|
|
||||||
|
test('renders learn react link', () => {
|
||||||
|
const { getByText } = render(<App />);
|
||||||
|
const linkElement = getByText(/learn react/i);
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
});
|
141
counter_kand/frontend/src/components/actionItems.js
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
import React, { Fragment } from 'react';
|
||||||
|
import {
|
||||||
|
withStyles,
|
||||||
|
Fab,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
|
import ListIcon from '@material-ui/icons/List';
|
||||||
|
import ShareIcon from '@material-ui/icons/Share';
|
||||||
|
import TouchAppIcon from '@material-ui/icons/TouchApp';
|
||||||
|
import UndoIcon from '@material-ui/icons/Undo';
|
||||||
|
import FullscreenIcon from '@material-ui/icons/Fullscreen';
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
disabled: {},
|
||||||
|
fabDelete: {
|
||||||
|
position: 'fixed',
|
||||||
|
top: theme.spacing(0.5),
|
||||||
|
right: theme.spacing(26.5),
|
||||||
|
zIndex: 100,
|
||||||
|
[theme.breakpoints.down('xs')]: {
|
||||||
|
right: theme.spacing(16.5),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fabCount: {
|
||||||
|
position: 'fixed',
|
||||||
|
top: theme.spacing(0.5),
|
||||||
|
right: theme.spacing(10.5),
|
||||||
|
zIndex: 100,
|
||||||
|
"&$disabled": {
|
||||||
|
backgroundColor: "#f50057",
|
||||||
|
color: "white"
|
||||||
|
},
|
||||||
|
[theme.breakpoints.down('xs')]: {
|
||||||
|
right: theme.spacing(9),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fabList: {
|
||||||
|
position: 'fixed',
|
||||||
|
top: theme.spacing(0.5),
|
||||||
|
right: theme.spacing(18.5),
|
||||||
|
zIndex: 100,
|
||||||
|
[theme.breakpoints.down('xs')]: {
|
||||||
|
visibility: "hidden"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fabShare: {
|
||||||
|
position: 'fixed',
|
||||||
|
top: theme.spacing(0.5),
|
||||||
|
right: theme.spacing(34.5),
|
||||||
|
zIndex: 100,
|
||||||
|
[theme.breakpoints.down('xs')]: {
|
||||||
|
visibility: "hidden"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fabToogle: {
|
||||||
|
position: 'fixed',
|
||||||
|
top: theme.spacing(0.5),
|
||||||
|
right: theme.spacing(42.5),
|
||||||
|
zIndex: 100,
|
||||||
|
[theme.breakpoints.down('xs')]: {
|
||||||
|
right: theme.spacing(24),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fabFullScreen: {
|
||||||
|
position: 'fixed',
|
||||||
|
top: theme.spacing(0.5),
|
||||||
|
right: theme.spacing(50.5),
|
||||||
|
zIndex: 100,
|
||||||
|
[theme.breakpoints.down('xs')]: {
|
||||||
|
right: theme.spacing(31.5),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function ActionItems(props) {
|
||||||
|
const { classes, toggleFullscreen, toogleIconView, shareLink, deleteLastMeasurement, measurementsCount, useCaseId } = props;
|
||||||
|
const to = "/useCases/" + useCaseId + "/measurements/view"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<Fab
|
||||||
|
color="secondary"
|
||||||
|
aria-label="export"
|
||||||
|
className={classes.fabFullScreen}
|
||||||
|
onClick={toggleFullscreen}
|
||||||
|
>
|
||||||
|
<FullscreenIcon />
|
||||||
|
</Fab>
|
||||||
|
|
||||||
|
<Fab
|
||||||
|
color="secondary"
|
||||||
|
aria-label="export"
|
||||||
|
className={classes.fabToogle}
|
||||||
|
onClick={toogleIconView}
|
||||||
|
>
|
||||||
|
<TouchAppIcon />
|
||||||
|
</Fab>
|
||||||
|
|
||||||
|
<Fab
|
||||||
|
color="secondary"
|
||||||
|
aria-label="export"
|
||||||
|
className={classes.fabShare}
|
||||||
|
onClick={shareLink}
|
||||||
|
>
|
||||||
|
<ShareIcon />
|
||||||
|
</Fab>
|
||||||
|
|
||||||
|
<Fab
|
||||||
|
color="secondary"
|
||||||
|
aria-label="export"
|
||||||
|
className={classes.fabDelete}
|
||||||
|
onClick={deleteLastMeasurement}
|
||||||
|
>
|
||||||
|
<UndoIcon />
|
||||||
|
</Fab>
|
||||||
|
|
||||||
|
<Fab
|
||||||
|
color="secondary"
|
||||||
|
aria-label="edit"
|
||||||
|
disabled={true}
|
||||||
|
className={classes.fabCount}
|
||||||
|
classes={{ disabled: classes.disabled }}
|
||||||
|
>
|
||||||
|
{measurementsCount}
|
||||||
|
</Fab>
|
||||||
|
|
||||||
|
<Fab
|
||||||
|
color="secondary"
|
||||||
|
aria-label="export"
|
||||||
|
className={classes.fabList}
|
||||||
|
component={Link}
|
||||||
|
to={to}
|
||||||
|
>
|
||||||
|
<ListIcon />
|
||||||
|
</Fab>
|
||||||
|
</Fragment>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withStyles(styles)(ActionItems);
|
75
counter_kand/frontend/src/components/appHeader.js
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import {
|
||||||
|
AppBar,
|
||||||
|
Toolbar,
|
||||||
|
Button,
|
||||||
|
Typography,
|
||||||
|
withStyles,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import HelpOutlineIcon from '@material-ui/icons/HelpOutline';
|
||||||
|
import Help from './help'
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
headerButton: {
|
||||||
|
position: 'fixed',
|
||||||
|
top: theme.spacing(-0.5),
|
||||||
|
right: theme.spacing(),
|
||||||
|
color: '#f50057',
|
||||||
|
[theme.breakpoints.down('xs')]: {
|
||||||
|
top: theme.spacing(-1),
|
||||||
|
right: theme.spacing(0),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
helpIcon: {
|
||||||
|
fontSize: '4.5em',
|
||||||
|
color: 'white',
|
||||||
|
},
|
||||||
|
toolBar: {
|
||||||
|
backgroundColor: "#ba4682",
|
||||||
|
padding: theme.spacing(1)
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
height: '40px'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function AppHeader(props) {
|
||||||
|
const { classes } = props
|
||||||
|
const [showHelp, setShowHelp] = useState(false)
|
||||||
|
|
||||||
|
const handleChange = () => {
|
||||||
|
setShowHelp(!showHelp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AppBar position="static">
|
||||||
|
<Toolbar className={classes.toolBar}>
|
||||||
|
<Button color="inherit" component={Link} to="/">
|
||||||
|
<img className={classes.image} src={`${window.location.origin}/images/header.png`} alt="Header" />
|
||||||
|
<Typography variant="h6" color="inherit">
|
||||||
|
Counter
|
||||||
|
</Typography>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={handleChange}
|
||||||
|
className={classes.headerButton}
|
||||||
|
>
|
||||||
|
<HelpOutlineIcon
|
||||||
|
color="secondary"
|
||||||
|
aria-label="add"
|
||||||
|
className={classes.helpIcon}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Help
|
||||||
|
handleChange={handleChange}
|
||||||
|
showModal={showHelp}
|
||||||
|
/>
|
||||||
|
</Toolbar>
|
||||||
|
</AppBar>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withStyles(styles)(AppHeader);
|
4
counter_kand/frontend/src/components/config.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
env: process.env.NODE_ENV,
|
||||||
|
port: process.env.port,
|
||||||
|
}
|
51
counter_kand/frontend/src/components/errorSnackbar.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import {
|
||||||
|
withStyles,
|
||||||
|
Snackbar,
|
||||||
|
SnackbarContent,
|
||||||
|
IconButton,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import { Error as ErrorIcon, Close as CloseIcon } from '@material-ui/icons';
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
snackbarContent: {
|
||||||
|
backgroundColor: theme.palette.error.dark,
|
||||||
|
},
|
||||||
|
message: {
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
icon: {
|
||||||
|
fontSize: 20,
|
||||||
|
},
|
||||||
|
iconVariant: {
|
||||||
|
opacity: 0.9,
|
||||||
|
marginRight: theme.spacing(1),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const ErrorSnackbar = ({ id, message, onClose, classes }) => (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
autoHideDuration={10000}
|
||||||
|
onClose={onClose}
|
||||||
|
>
|
||||||
|
<SnackbarContent
|
||||||
|
className={`${classes.margin} ${classes.snackbarContent}`}
|
||||||
|
aria-describedby={id}
|
||||||
|
message={
|
||||||
|
<span id={id} className={classes.message}>
|
||||||
|
<ErrorIcon className={`${classes.icon} ${classes.iconVariant}`} />
|
||||||
|
{message}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
action={[
|
||||||
|
<IconButton key="close" aria-label="Close" color="inherit" onClick={onClose}>
|
||||||
|
<CloseIcon className={classes.icon} />
|
||||||
|
</IconButton>
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Snackbar>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default withStyles(styles)(ErrorSnackbar);
|
92
counter_kand/frontend/src/components/help.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
import React, { Fragment, useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
withStyles,
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardActions,
|
||||||
|
Modal,
|
||||||
|
Button,
|
||||||
|
Typography,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import ClearIcon from '@material-ui/icons/Clear';
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
modal: {
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
modalCard: {
|
||||||
|
width: '90%',
|
||||||
|
maxWidth: 600,
|
||||||
|
},
|
||||||
|
modalCardContent: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
},
|
||||||
|
marginTop: {
|
||||||
|
marginTop: theme.spacing(5),
|
||||||
|
},
|
||||||
|
textCenter: {
|
||||||
|
margin: 'auto'
|
||||||
|
},
|
||||||
|
images: {
|
||||||
|
width: '100%'
|
||||||
|
},
|
||||||
|
links: {
|
||||||
|
textDecoration: 'none',
|
||||||
|
color: 'black'
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
marginTop: theme.spacing(2)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function Help(props) {
|
||||||
|
const { classes } = props;
|
||||||
|
const APP_VERSION = process.env.REACT_APP_VERSION
|
||||||
|
const [showModal, setShowModal] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (showModal !== props.showModal) {
|
||||||
|
setShowModal(props.showModal);
|
||||||
|
}
|
||||||
|
}, [props.showModal, showModal]);
|
||||||
|
|
||||||
|
const handleChange = () => {
|
||||||
|
let parentHandler = props.handleChange
|
||||||
|
setShowModal(!showModal);
|
||||||
|
parentHandler()
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
{showModal && (
|
||||||
|
<Modal
|
||||||
|
className={classes.modal}
|
||||||
|
onClose={handleChange}
|
||||||
|
open
|
||||||
|
>
|
||||||
|
<Card className={`${classes.modalCard} ${classes.marginTop}`}>
|
||||||
|
<CardContent className={classes.modalCardContent}>
|
||||||
|
<Typography variant="h6">About the app</Typography>
|
||||||
|
<Typography> Provides a simple and easy to use interface for creating custimized measurements. </Typography>
|
||||||
|
<Typography>Measurments are grouped within a use case. For a use case the counting buttons can be defined.</Typography>
|
||||||
|
<Typography> When clicking on a button the timestamp and bottom value is stored. The stored values can be easily exported.</Typography>
|
||||||
|
<Typography>App version: {APP_VERSION}</Typography>
|
||||||
|
|
||||||
|
<Typography variant="h6" className={classes.header}>Disclaimer</Typography>
|
||||||
|
<Typography>This counter tool is provided as is, and no support will be given. Querying a large amount of data within a very short time, for example by automated means, is prohibited. The developers and any other person be liable to any person for any damage or loss that may arise from the use of this couter tool. Please be aware that the use of this counter tool will be deemed as agreeing to the terms of these conditions.</Typography>
|
||||||
|
</CardContent>
|
||||||
|
<CardActions>
|
||||||
|
<Button size="small" onClick={handleChange}><ClearIcon />Close</Button>
|
||||||
|
</CardActions>
|
||||||
|
</Card>
|
||||||
|
</Modal>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</Fragment>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withStyles(styles)(Help);
|
52
counter_kand/frontend/src/components/infoSnackbar.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import {
|
||||||
|
withStyles,
|
||||||
|
Snackbar,
|
||||||
|
SnackbarContent,
|
||||||
|
IconButton,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import { Check as CheckIcon, Close as CloseIcon } from '@material-ui/icons';
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
snackbarContent: {
|
||||||
|
backgroundColor: theme.palette.success.dark,
|
||||||
|
},
|
||||||
|
message: {
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
icon: {
|
||||||
|
fontSize: 20,
|
||||||
|
},
|
||||||
|
iconVariant: {
|
||||||
|
opacity: 0.9,
|
||||||
|
marginRight: theme.spacing(1),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const AUTO_HIDE_DURATION = 10000
|
||||||
|
|
||||||
|
const InfoSnackbar = ({ id, message, onClose, classes }) => (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
autoHideDuration={AUTO_HIDE_DURATION}
|
||||||
|
onClose={onClose}
|
||||||
|
>
|
||||||
|
<SnackbarContent
|
||||||
|
className={`${classes.margin} ${classes.snackbarContent}`}
|
||||||
|
aria-describedby={id}
|
||||||
|
message={
|
||||||
|
<span id={id} className={classes.message}>
|
||||||
|
<CheckIcon className={`${classes.icon} ${classes.iconVariant}`} />
|
||||||
|
{message}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
action={[
|
||||||
|
<IconButton key="close" aria-label="Close" color="inherit" onClick={onClose}>
|
||||||
|
<CloseIcon className={classes.icon} />
|
||||||
|
</IconButton>
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Snackbar>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default withStyles(styles)(InfoSnackbar);
|
22
counter_kand/frontend/src/components/loadingBar.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import {
|
||||||
|
withStyles,
|
||||||
|
CircularProgress
|
||||||
|
} from '@material-ui/core';
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
loadingBar: {
|
||||||
|
fontSize: 100,
|
||||||
|
position: 'fixed',
|
||||||
|
top: "10vh",
|
||||||
|
marginLeft: '50%'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const LoadingBar = ({ classes }) => (
|
||||||
|
<div className={classes.root}>
|
||||||
|
<CircularProgress className={classes.loadingBar} size={100} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default withStyles(styles)(LoadingBar);
|
57
counter_kand/frontend/src/components/measurementButton.js
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
withStyles,
|
||||||
|
Button,
|
||||||
|
Icon
|
||||||
|
} from '@material-ui/core';
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
button: props => ({
|
||||||
|
width: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
minHeight: '10vh',
|
||||||
|
overflow: "hidden",
|
||||||
|
wordBreak: 'break-all',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
function MeasurementButton(props) {
|
||||||
|
const { classes, displayText } = props;
|
||||||
|
|
||||||
|
const [groupName, setGroupName] = useState("");
|
||||||
|
const [buttonValue, setButtonValue] = useState("");
|
||||||
|
const [icon, setIcon] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setGroupName(props.groupName);
|
||||||
|
setButtonValue(props.buttonValue);
|
||||||
|
setIcon(props.icon);
|
||||||
|
}, [props.groupName, props.buttonValue, props.icon]);
|
||||||
|
|
||||||
|
const handleButtonPress = () => {
|
||||||
|
const { onClick } = props
|
||||||
|
onClick(groupName, buttonValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button variant="outlined"
|
||||||
|
color="primary"
|
||||||
|
className={classes.button}
|
||||||
|
onClick={handleButtonPress}
|
||||||
|
>
|
||||||
|
{ /* display text only if user wants that */}
|
||||||
|
{displayText && (
|
||||||
|
buttonValue
|
||||||
|
)}
|
||||||
|
<br />
|
||||||
|
|
||||||
|
{icon && (
|
||||||
|
<Icon>{icon}</Icon>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withStyles(styles)(MeasurementButton);
|
138
counter_kand/frontend/src/components/measurementOptions.js
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
TextField,
|
||||||
|
withStyles,
|
||||||
|
Button,
|
||||||
|
InputLabel,
|
||||||
|
MenuItem,
|
||||||
|
Select
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import AddIcon from '@material-ui/icons/Add';
|
||||||
|
import Icon from '@material-ui/core/Icon';
|
||||||
|
import DeleteIcon from '@material-ui/icons/Delete';
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
iconLabel: {
|
||||||
|
display: "inline"
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
marginTop: theme.spacing(1.5)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Definition of Icons which can be used for buttons
|
||||||
|
// source https://material.io/resources/icons/?icon=arrow_downward&style=baseline
|
||||||
|
const ICONS = ["", "arrow_back", "arrow_forward", "arrow_upward", "arrow_downward",
|
||||||
|
"swap_horiz", "swap_vert", "accessible", "commute", "flight_land",
|
||||||
|
"flight_takeoff", "work", "login", "logout", "pedal_bike", "directions_walk",
|
||||||
|
"directions_car", "directions_bus", "directions_railway", "tram", "electric_bike",
|
||||||
|
"electric_car", "local_taxi", "electric_scooter", "two_wheeler", "north_east", "north_west",
|
||||||
|
"south_east", "south_west", "child_friendly", "elderly", "skateboarding"]
|
||||||
|
|
||||||
|
function MeasurementOptions(props) {
|
||||||
|
const { classes } = props;
|
||||||
|
|
||||||
|
const [options, setOptions] = useState([]);
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
const [id, setId] = useState(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setOptions(props.options);
|
||||||
|
setName(props.name);
|
||||||
|
setId(props.id);
|
||||||
|
}, [props.options, props.name, props.id]);
|
||||||
|
|
||||||
|
// updates the measurement option on the given index with the given event value
|
||||||
|
const handleMeasurementOptionChange = idx => evt => {
|
||||||
|
const { handleOptionChange } = props
|
||||||
|
const newOptions = options.map((option, sidx) => {
|
||||||
|
if (idx !== sidx) return option
|
||||||
|
|
||||||
|
// check which information has been updated, either option name or option icon
|
||||||
|
if (evt.target.name === "optionName") {
|
||||||
|
return { name: evt.target.value, icon: option.icon }
|
||||||
|
} else {
|
||||||
|
return { name: option.name, icon: evt.target.value }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setOptions(newOptions);
|
||||||
|
|
||||||
|
// execute parent function in usecaseEditor
|
||||||
|
handleOptionChange(id, newOptions);
|
||||||
|
};
|
||||||
|
|
||||||
|
// add measurement option
|
||||||
|
const handleAddMeasurementOption = () => {
|
||||||
|
setOptions(options.concat([{ name: "", icon: "" }]));
|
||||||
|
};
|
||||||
|
|
||||||
|
// remove measurement option
|
||||||
|
const handleRemoveMeasurementOption = idx => () => {
|
||||||
|
const { handleOptionChange } = props
|
||||||
|
let tempOptions = options.filter((s, sidx) => idx !== sidx)
|
||||||
|
|
||||||
|
setOptions(tempOptions);
|
||||||
|
|
||||||
|
// update parent state
|
||||||
|
handleOptionChange(id, tempOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{options.map((option, idx) => (
|
||||||
|
<div className={classes.options} key={`div-${idx + 1}`}>
|
||||||
|
<TextField
|
||||||
|
required
|
||||||
|
key={idx + 1}
|
||||||
|
name="optionName"
|
||||||
|
type="text"
|
||||||
|
label="Option name"
|
||||||
|
placeholder={`Option #${idx + 1} name`}
|
||||||
|
value={option.name}
|
||||||
|
onChange={handleMeasurementOptionChange(idx)}
|
||||||
|
variant="outlined"
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<InputLabel id="labelIconOption" className={classes.iconLabel}>Icon</InputLabel>
|
||||||
|
<Select
|
||||||
|
labelId="labelIconOption"
|
||||||
|
name="optionIcon"
|
||||||
|
id="optionIcon"
|
||||||
|
value={option.icon}
|
||||||
|
onChange={handleMeasurementOptionChange(idx)}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
ICONS.map((icon, i) => (
|
||||||
|
<MenuItem key={i} value={icon}>
|
||||||
|
{<Icon>{icon}</Icon>}
|
||||||
|
</MenuItem>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
color="primary"
|
||||||
|
type="button"
|
||||||
|
onClick={handleRemoveMeasurementOption(idx)}
|
||||||
|
>
|
||||||
|
<DeleteIcon /> Remove Option
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
color="primary"
|
||||||
|
type="button"
|
||||||
|
onClick={handleAddMeasurementOption}
|
||||||
|
>
|
||||||
|
<AddIcon /> Add Option
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withStyles(styles)(MeasurementOptions);
|
227
counter_kand/frontend/src/components/useCaseEditor.js
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
TextField,
|
||||||
|
withStyles,
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardActions,
|
||||||
|
Modal,
|
||||||
|
Button,
|
||||||
|
Typography,
|
||||||
|
FormGroup
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import DeleteIcon from '@material-ui/icons/Delete';
|
||||||
|
import AddIcon from '@material-ui/icons/Add';
|
||||||
|
import SaveAltIcon from '@material-ui/icons/SaveAlt';
|
||||||
|
import ClearIcon from '@material-ui/icons/Clear';
|
||||||
|
import FileCopyIcon from '@material-ui/icons/FileCopy';
|
||||||
|
|
||||||
|
import './utensils'
|
||||||
|
import MeasurementOptions from './measurementOptions'
|
||||||
|
import { deepCopy } from './utensils';
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
modal: {
|
||||||
|
display: 'flex',
|
||||||
|
outline: 0,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
modalCard: {
|
||||||
|
width: '100%',
|
||||||
|
maxWidth: 800,
|
||||||
|
maxHeight: "100%",
|
||||||
|
overflow: "scroll"
|
||||||
|
},
|
||||||
|
modalCardContent: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
},
|
||||||
|
marginTop: {
|
||||||
|
marginTop: theme.spacing(2),
|
||||||
|
},
|
||||||
|
formGroup: {
|
||||||
|
border: 'solid',
|
||||||
|
borderWidth: '1px',
|
||||||
|
padding: theme.spacing(1)
|
||||||
|
},
|
||||||
|
inputField: {
|
||||||
|
marginTop: theme.spacing(1)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function UseCaseditor(props) {
|
||||||
|
const { classes, useCase, useCaseEditorMode, errorMessage, onSave, onClose } = props;
|
||||||
|
|
||||||
|
const [id, setId] = useState(0);
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
const [pinCode, setPinCode] = useState("");
|
||||||
|
const [measurementOptions, setMeasurementOptions] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (useCaseEditorMode === "edit") {
|
||||||
|
setId(useCase.id);
|
||||||
|
setName(useCase.name);
|
||||||
|
setMeasurementOptions(useCase.measurementOptions);
|
||||||
|
} else if (useCaseEditorMode === "copy") {
|
||||||
|
let newUseCase = deepCopy(useCase)
|
||||||
|
newUseCase.name = newUseCase.name + " (Copy)"
|
||||||
|
|
||||||
|
setId(null);
|
||||||
|
setName("Copy " + newUseCase.name);
|
||||||
|
setMeasurementOptions(newUseCase.measurementOptions);
|
||||||
|
}
|
||||||
|
}, [useCase, useCaseEditorMode]);
|
||||||
|
|
||||||
|
// called by child MeasurementOptions when change of input
|
||||||
|
const handleOptionChange = function (groupIndex, options) {
|
||||||
|
let tmpOptions = measurementOptions
|
||||||
|
|
||||||
|
tmpOptions[groupIndex].options = options
|
||||||
|
setMeasurementOptions(tmpOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
// function handling submit of form
|
||||||
|
const handleSubmit = evt => {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
|
// execute parent function in useCaseManager
|
||||||
|
onSave(id, name, pinCode, measurementOptions)
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOptionGroupName = (index, event) => {
|
||||||
|
let tempMeasurementOptions = deepCopy(measurementOptions)
|
||||||
|
tempMeasurementOptions[index].name = event.target.value
|
||||||
|
setMeasurementOptions(tempMeasurementOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleChange = (evt) => {
|
||||||
|
const target = evt.target
|
||||||
|
const name = target.name
|
||||||
|
let value = target.value
|
||||||
|
|
||||||
|
switch (name) {
|
||||||
|
case "name":
|
||||||
|
setName(value)
|
||||||
|
break
|
||||||
|
case "pinCode":
|
||||||
|
setPinCode(value)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleAddOptionGroup = () => {
|
||||||
|
let idx = measurementOptions.length
|
||||||
|
|
||||||
|
setMeasurementOptions(measurementOptions.concat([{ id: idx, name: "", options: [{ name: "", icon: "" }] }]))
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveOptionGroup = idx => () => {
|
||||||
|
setMeasurementOptions(measurementOptions.filter((s, sidx) => idx !== sidx));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCopyOptionGroup = idx => () => {
|
||||||
|
let tempMeasurementOptions = measurementOptions
|
||||||
|
let newMeasurementOption = { ...tempMeasurementOptions[idx] }
|
||||||
|
newMeasurementOption.id = tempMeasurementOptions.length
|
||||||
|
tempMeasurementOptions.insert(idx, newMeasurementOption)
|
||||||
|
setMeasurementOptions(tempMeasurementOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
className={classes.modal}
|
||||||
|
onClose={() => onClose()}
|
||||||
|
open
|
||||||
|
>
|
||||||
|
<Card className={classes.modalCard}>
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<CardContent className={classes.modalCardContent}>
|
||||||
|
<TextField
|
||||||
|
required
|
||||||
|
type="text"
|
||||||
|
name="name"
|
||||||
|
key="inputUseCase"
|
||||||
|
placeholder="Use Case Name"
|
||||||
|
label="Use Case Name"
|
||||||
|
value={name}
|
||||||
|
onChange={handleChange}
|
||||||
|
variant="outlined"
|
||||||
|
size="small"
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
required
|
||||||
|
type="text"
|
||||||
|
key="inputUseCasePinCode"
|
||||||
|
name="pinCode"
|
||||||
|
placeholder="Use Case Pin Code"
|
||||||
|
label="Use Case Pin Code"
|
||||||
|
className={classes.inputField}
|
||||||
|
value={pinCode}
|
||||||
|
onChange={handleChange}
|
||||||
|
error={errorMessage}
|
||||||
|
variant="outlined"
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Typography variant="subtitle1" >Measurement Options</Typography>
|
||||||
|
{measurementOptions && measurementOptions.length > 0 && measurementOptions.map(function (element, index) {
|
||||||
|
return (
|
||||||
|
<FormGroup key={`formgroup-${index}`} className={classes.formGroup}>
|
||||||
|
<TextField
|
||||||
|
required
|
||||||
|
type="text"
|
||||||
|
key={`input-optionGroup-${index}`}
|
||||||
|
placeholder="Option group name"
|
||||||
|
label="Option group name"
|
||||||
|
value={element.name}
|
||||||
|
onChange={(evt) => handleOptionGroupName(index, evt)}
|
||||||
|
variant="outlined"
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<MeasurementOptions
|
||||||
|
id={index}
|
||||||
|
name={element.name}
|
||||||
|
options={element.options}
|
||||||
|
handleOptionChange={handleOptionChange}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
color="primary"
|
||||||
|
className={classes.button}
|
||||||
|
onClick={handleRemoveOptionGroup(index)}
|
||||||
|
>
|
||||||
|
<DeleteIcon />Remove Option Group
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
color="primary"
|
||||||
|
className={classes.button}
|
||||||
|
onClick={handleCopyOptionGroup(index)}
|
||||||
|
>
|
||||||
|
<FileCopyIcon />Copy Option Group
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</FormGroup>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</CardContent>
|
||||||
|
<CardActions>
|
||||||
|
<Button size="small" color="primary" type="submit"><SaveAltIcon />Save</Button>
|
||||||
|
<Button size="small" color="primary" onClick={handleAddOptionGroup}><AddIcon />Add Option Group</Button>
|
||||||
|
<Button size="small" onClick={onClose}><ClearIcon />Cancel</Button>
|
||||||
|
</CardActions>
|
||||||
|
</form>
|
||||||
|
</Card>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withStyles(styles)(UseCaseditor);
|
9
counter_kand/frontend/src/components/utensils.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// function which allows to insert object at at given index
|
||||||
|
// eslint-disable-next-line
|
||||||
|
Array.prototype.insert = function (index, item) {
|
||||||
|
this.splice(index, 0, item);
|
||||||
|
};
|
||||||
|
|
||||||
|
export function deepCopy(obj) {
|
||||||
|
return JSON.parse(JSON.stringify(obj));
|
||||||
|
}
|
20
counter_kand/frontend/src/index.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
|
import App from './components/App';
|
||||||
|
import * as serviceWorker from './serviceWorker';
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<BrowserRouter>
|
||||||
|
<App />
|
||||||
|
</BrowserRouter>,
|
||||||
|
document.getElementById('root')
|
||||||
|
);
|
||||||
|
|
||||||
|
// If you want your app to work offline and load faster, you can change
|
||||||
|
// unregister() to register() below. Note this comes with some pitfalls.
|
||||||
|
// Learn more about service workers: https://bit.ly/CRA-PWA
|
||||||
|
serviceWorker.unregister();
|
||||||
|
|
||||||
|
// enable hotswapping of modules
|
||||||
|
if (module.hot) module.hot.accept();
|
180
counter_kand/frontend/src/pages/measurementView.js
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
import React, { useState, Fragment, forwardRef, useEffect } from 'react';
|
||||||
|
import {
|
||||||
|
withStyles,
|
||||||
|
Typography,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import { useParams } from 'react-router-dom';
|
||||||
|
|
||||||
|
// icons for material table
|
||||||
|
import AddBox from '@material-ui/icons/AddBox';
|
||||||
|
import ArrowDownward from '@material-ui/icons/ArrowDownward';
|
||||||
|
import Check from '@material-ui/icons/Check';
|
||||||
|
import ChevronLeft from '@material-ui/icons/ChevronLeft';
|
||||||
|
import ChevronRight from '@material-ui/icons/ChevronRight';
|
||||||
|
import Clear from '@material-ui/icons/Clear';
|
||||||
|
import DeleteOutline from '@material-ui/icons/DeleteOutline';
|
||||||
|
import Edit from '@material-ui/icons/Edit';
|
||||||
|
import FilterList from '@material-ui/icons/FilterList';
|
||||||
|
import FirstPage from '@material-ui/icons/FirstPage';
|
||||||
|
import LastPage from '@material-ui/icons/LastPage';
|
||||||
|
import Remove from '@material-ui/icons/Remove';
|
||||||
|
import SaveAlt from '@material-ui/icons/SaveAlt';
|
||||||
|
import Search from '@material-ui/icons/Search';
|
||||||
|
import ViewColumn from '@material-ui/icons/ViewColumn';
|
||||||
|
import MaterialTable from 'material-table'
|
||||||
|
|
||||||
|
import ErrorSnackbar from '../components/errorSnackbar';
|
||||||
|
import LoadingBar from '../components/loadingBar'
|
||||||
|
|
||||||
|
const API = window.env.BACKEND_URL;
|
||||||
|
|
||||||
|
// definition used for material table
|
||||||
|
const tableIcons = {
|
||||||
|
Add: forwardRef((props, ref) => <AddBox {...props} ref={ref} />),
|
||||||
|
Check: forwardRef((props, ref) => <Check {...props} ref={ref} />),
|
||||||
|
Clear: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
|
||||||
|
Delete: forwardRef((props, ref) => <DeleteOutline {...props} ref={ref} />),
|
||||||
|
DetailPanel: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
|
||||||
|
Edit: forwardRef((props, ref) => <Edit {...props} ref={ref} />),
|
||||||
|
Export: forwardRef((props, ref) => <SaveAlt {...props} ref={ref} />),
|
||||||
|
Filter: forwardRef((props, ref) => <FilterList {...props} ref={ref} />),
|
||||||
|
FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
|
||||||
|
LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
|
||||||
|
NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
|
||||||
|
PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />),
|
||||||
|
ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
|
||||||
|
Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
|
||||||
|
SortArrow: forwardRef((props, ref) => <ArrowDownward {...props} ref={ref} />),
|
||||||
|
ThirdStateCheck: forwardRef((props, ref) => <Remove {...props} ref={ref} />),
|
||||||
|
ViewColumn: forwardRef((props, ref) => <ViewColumn {...props} ref={ref} />)
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
});
|
||||||
|
|
||||||
|
const getDateTime = () => {
|
||||||
|
const today = new Date();
|
||||||
|
const date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
|
||||||
|
const time = today.getHours() + "-" + today.getMinutes() + "-" + today.getSeconds();
|
||||||
|
|
||||||
|
return date + '_' + time;
|
||||||
|
}
|
||||||
|
|
||||||
|
function MeasurementView(props) {
|
||||||
|
const { id } = useParams();
|
||||||
|
const [useCase, setUseCase] = useState("");
|
||||||
|
const [measurements, setMeasurements] = useState([]);
|
||||||
|
const [tableOutput, setTableOutput] = useState([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const title = "List measurements for " + useCase.name // define title of website
|
||||||
|
const exportFileName = "list_measurements_" + useCase.name + "_" + getDateTime() // define export file name
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getMeasurements();
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
const custom_fetch = async (method, endpoint, body) => {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API}/api${endpoint}`, {
|
||||||
|
method,
|
||||||
|
body: body && JSON.stringify(body),
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
accept: 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
|
||||||
|
if (response.ok && (response.status === 201 || response.status === 200)) {
|
||||||
|
return await response.json();
|
||||||
|
} else {
|
||||||
|
console.error(response.status)
|
||||||
|
setError({ message: "Error when communicating with backend: " + response.statusText })
|
||||||
|
|
||||||
|
throw new Error("Error communicating with backend")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
setError(error)
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getMeasurements = async () => {
|
||||||
|
const useCaseId = id
|
||||||
|
|
||||||
|
// get use case and corresponding measurements
|
||||||
|
let useCase = (await custom_fetch('get', '/usecases/' + useCaseId + "/measurements")) || []
|
||||||
|
let measurements = useCase.Measurements
|
||||||
|
let tableOutput = []
|
||||||
|
|
||||||
|
if (measurements) {
|
||||||
|
measurements.forEach(measurement => {
|
||||||
|
tableOutput.push({
|
||||||
|
useCase: useCase.name,
|
||||||
|
groupName: measurement.groupName,
|
||||||
|
value: measurement.value,
|
||||||
|
timestamp: measurement.timestamp.split("+")[0]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
setUseCase(useCase)
|
||||||
|
setMeasurements(tableOutput)
|
||||||
|
setTableOutput(tableOutput)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
{measurements && measurements.length > 0 ? (
|
||||||
|
// data available, present table
|
||||||
|
<MaterialTable
|
||||||
|
icons={tableIcons}
|
||||||
|
title={title}
|
||||||
|
columns={[
|
||||||
|
{ title: 'Use case', field: 'useCase', },
|
||||||
|
{ title: 'Measurement group', field: 'groupName' },
|
||||||
|
{ title: 'Measurement value', field: 'value' },
|
||||||
|
{ title: 'Timestamp', field: 'timestamp' }
|
||||||
|
]}
|
||||||
|
data={tableOutput}
|
||||||
|
options={{
|
||||||
|
exportFileName: exportFileName,
|
||||||
|
exportButton: true,
|
||||||
|
exportAllData: true,
|
||||||
|
filtering: true,
|
||||||
|
search: false,
|
||||||
|
pageSize: 5,
|
||||||
|
pageSizeOptions: [5, 10, 20, 50],
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
// no data available
|
||||||
|
!loading && (
|
||||||
|
<Typography variant="subtitle1">So far no measurements have been recorded for use case {useCase.name}</Typography>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
|
||||||
|
{ /* Flag based display of error snackbar */}
|
||||||
|
{error && (
|
||||||
|
<ErrorSnackbar
|
||||||
|
onClose={() => setError(null)}
|
||||||
|
message={error.message}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{ /* Flag based display of loadingbar */}
|
||||||
|
{loading && (
|
||||||
|
<LoadingBar />
|
||||||
|
)}
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withStyles(styles)(MeasurementView);
|
264
counter_kand/frontend/src/pages/useCaseManager.js
Normal file
@ -0,0 +1,264 @@
|
|||||||
|
import React, { useEffect, useState, Fragment } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import {
|
||||||
|
withStyles,
|
||||||
|
Typography,
|
||||||
|
Fab,
|
||||||
|
IconButton,
|
||||||
|
Paper,
|
||||||
|
List,
|
||||||
|
ListItem,
|
||||||
|
ListItemText,
|
||||||
|
ListItemSecondaryAction,
|
||||||
|
TextField
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import { Delete as DeleteIcon, Create as CreateIcon, Add as AddIcon } from '@material-ui/icons';
|
||||||
|
import FileCopyIcon from '@material-ui/icons/FileCopy';
|
||||||
|
import moment from 'moment';
|
||||||
|
import { orderBy, filter } from 'lodash';
|
||||||
|
|
||||||
|
import UseCaseEditor from '../components/useCaseEditor';
|
||||||
|
import ErrorSnackbar from '../components/errorSnackbar';
|
||||||
|
import LoadingBar from '../components/loadingBar'
|
||||||
|
import InfoSnackbar from '../components/infoSnackbar'
|
||||||
|
|
||||||
|
const API = window.env.BACKEND_URL;
|
||||||
|
|
||||||
|
const styles = theme => ({
|
||||||
|
useCaseDiv: {
|
||||||
|
marginTop: theme.spacing(2),
|
||||||
|
outline: 0,
|
||||||
|
},
|
||||||
|
fab: {
|
||||||
|
position: 'absolute',
|
||||||
|
bottom: theme.spacing(3),
|
||||||
|
right: theme.spacing(3),
|
||||||
|
[theme.breakpoints.down('xs')]: {
|
||||||
|
bottom: theme.spacing(2),
|
||||||
|
right: theme.spacing(2),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
serachDiv: {
|
||||||
|
marginBottom: theme.spacing(1)
|
||||||
|
},
|
||||||
|
searchInput: {
|
||||||
|
width: "100%",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function UseCaseManager(props) {
|
||||||
|
const { classes } = props;
|
||||||
|
// use case
|
||||||
|
const [query, setQuery] = useState("");
|
||||||
|
const [useCases, setUseCases] = useState([]);
|
||||||
|
const [useCasesFiltered, setUseCasesFiltered] = useState([]);
|
||||||
|
|
||||||
|
// use case editor
|
||||||
|
const [useCase, setUseCase] = useState(null);
|
||||||
|
const [useCaseEditorOpen, setUseCaseEditorOpen] = useState(false);
|
||||||
|
const [useCaseEditorMode, setUseCaseEditorMode] = useState("create");
|
||||||
|
|
||||||
|
// general
|
||||||
|
const [success, setSuccess] = useState(null);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getUseCases();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let filteredObjects = filter(useCases, function (obj) {
|
||||||
|
return obj.name.toUpperCase().includes(query.toUpperCase());
|
||||||
|
})
|
||||||
|
|
||||||
|
setUseCasesFiltered(filteredObjects);
|
||||||
|
}, [query, useCases]);
|
||||||
|
|
||||||
|
const custom_fetch = async (method, endpoint, body) => {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API}/api${endpoint}`, {
|
||||||
|
method,
|
||||||
|
body: body && JSON.stringify(body),
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
accept: 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
|
||||||
|
if (response.ok && (response.status === 201 || response.status === 200)) {
|
||||||
|
return await response.json();
|
||||||
|
} else {
|
||||||
|
console.error(response.status)
|
||||||
|
setError({ message: "Error when communicating with backend: " + response.statusText })
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
setError(error)
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getUseCases = () => {
|
||||||
|
custom_fetch('get', '/useCases')
|
||||||
|
.then(useCases => {
|
||||||
|
setUseCases(useCases);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const onSaveUseCase = async (id, name, pinCode, measurementOptions) => {
|
||||||
|
const postData = {
|
||||||
|
name: name,
|
||||||
|
pinCode: pinCode,
|
||||||
|
measurementOptions: measurementOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id) {
|
||||||
|
await custom_fetch('put', `/useCases/${id}`, postData);
|
||||||
|
} else {
|
||||||
|
await custom_fetch('post', '/useCases', postData);
|
||||||
|
}
|
||||||
|
|
||||||
|
getUseCases()
|
||||||
|
|
||||||
|
if (error === null) {
|
||||||
|
setUseCaseEditorOpen(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteUseCase = async (useCase) => {
|
||||||
|
if (window.confirm(`Are you sure you want to delete "${useCase.name}"`)) {
|
||||||
|
// delete also all measurements
|
||||||
|
let measurements = await custom_fetch('get', `/useCases/${useCase.id}/measurements`);
|
||||||
|
|
||||||
|
custom_fetch('delete', `/useCases/${useCase.id}`);
|
||||||
|
|
||||||
|
measurements.measurementOptions.forEach(function (element) {
|
||||||
|
custom_fetch('delete', `/measurements/${element.id}`);
|
||||||
|
})
|
||||||
|
|
||||||
|
if (error === null) {
|
||||||
|
setSuccess("Use case successfully deleted")
|
||||||
|
}
|
||||||
|
|
||||||
|
getUseCases();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSearchChange = evt => {
|
||||||
|
setQuery(evt.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditorOpen = (useCase, mode) => {
|
||||||
|
setUseCase(useCase);
|
||||||
|
setUseCaseEditorMode(mode);
|
||||||
|
setUseCaseEditorOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<Typography variant="h4">Use Cases</Typography>
|
||||||
|
{ /* use case area */}
|
||||||
|
{useCases && useCases.length > 0 ? (
|
||||||
|
// usecases available
|
||||||
|
<Paper elevation={1} className={classes.useCaseDiv}>
|
||||||
|
<div className={classes.serachDiv}>
|
||||||
|
<TextField
|
||||||
|
required
|
||||||
|
type="text"
|
||||||
|
key="inputQuery"
|
||||||
|
placeholder="Search"
|
||||||
|
label="Search"
|
||||||
|
className={classes.searchInput}
|
||||||
|
value={query}
|
||||||
|
onChange={handleSearchChange}
|
||||||
|
variant="outlined"
|
||||||
|
size="small"
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<List>
|
||||||
|
{orderBy(useCasesFiltered, ['updatedAt', 'name'], ['desc', 'asc']).map(useCase => (
|
||||||
|
<ListItem key={useCase.id} button component={Link} to={`/useCases/${useCase.id}/measurements`}>
|
||||||
|
<ListItemText
|
||||||
|
primary={useCase.name}
|
||||||
|
secondary={useCase.updatedAt && `Updated ${moment(useCase.updatedAt).fromNow()}`}
|
||||||
|
/>
|
||||||
|
<ListItemSecondaryAction>
|
||||||
|
<IconButton component={Link} onClick={() => handleEditorOpen(useCase, "copy")} color="inherit">
|
||||||
|
<FileCopyIcon />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton component={Link} onClick={() => handleEditorOpen(useCase, "edit")} color="inherit">
|
||||||
|
<CreateIcon />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton onClick={() => deleteUseCase(useCase)} color="inherit">
|
||||||
|
<DeleteIcon />
|
||||||
|
</IconButton>
|
||||||
|
</ListItemSecondaryAction>
|
||||||
|
</ListItem>
|
||||||
|
))}
|
||||||
|
</List>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
|
||||||
|
) : (
|
||||||
|
// no usecases available
|
||||||
|
!loading && (
|
||||||
|
<Typography variant="subtitle1">So far no use cases have been created</Typography>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Fragment>
|
||||||
|
<Fab
|
||||||
|
color="secondary"
|
||||||
|
aria-label="add"
|
||||||
|
className={classes.fab}
|
||||||
|
component={Link}
|
||||||
|
onClick={() => { handleEditorOpen(null, 'create') }}
|
||||||
|
>
|
||||||
|
<AddIcon />
|
||||||
|
</Fab>
|
||||||
|
</Fragment>
|
||||||
|
|
||||||
|
{ /* Use Case Editor */}
|
||||||
|
{useCaseEditorOpen && (
|
||||||
|
<UseCaseEditor
|
||||||
|
useCase={useCase}
|
||||||
|
useCaseEditorMode={useCaseEditorMode}
|
||||||
|
errorMessage={error}
|
||||||
|
onSave={onSaveUseCase}
|
||||||
|
onClose={() => { setUseCaseEditorOpen(false) }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{ /* Flag based display of loadingbar */}
|
||||||
|
{loading && (
|
||||||
|
<LoadingBar />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{ /* Flag based display of error snackbar */}
|
||||||
|
{error && (
|
||||||
|
<ErrorSnackbar
|
||||||
|
onClose={() => setError(null)}
|
||||||
|
message={error.message}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{ /* Flag based display of info snackbar */}
|
||||||
|
{success && (
|
||||||
|
<InfoSnackbar
|
||||||
|
onClose={() => setSuccess(null)}
|
||||||
|
message={success}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withStyles(styles)(UseCaseManager);
|
289
counter_kand/frontend/src/pages/useCaseMeasurement.js
Normal file
@ -0,0 +1,289 @@
|
|||||||
|
import React, { useState, Fragment, useEffect } from 'react';
|
||||||
|
import {
|
||||||
|
withStyles,
|
||||||
|
Typography,
|
||||||
|
Grid
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import { useParams, useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
|
import ActionItems from '../components/actionItems';
|
||||||
|
import ErrorSnackbar from '../components/errorSnackbar';
|
||||||
|
import MeasurementButtons from '../components/measurementButton';
|
||||||
|
import InfoSnackbar from '..//components/infoSnackbar'
|
||||||
|
|
||||||
|
const API = window.env.BACKEND_URL;
|
||||||
|
const REXECUTION_TIMEOUT = 5000 // rexecution timeout for retry of the failed fetch calls
|
||||||
|
const styles = theme => ({
|
||||||
|
root: {
|
||||||
|
flexGrow: 1,
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: theme.spacing(4.5),
|
||||||
|
left: theme.spacing(13.5),
|
||||||
|
color: 'white'
|
||||||
|
},
|
||||||
|
measurementGroupTitle: {
|
||||||
|
fontSize: "5vh"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function UseCaseMeasurement(props) {
|
||||||
|
const { classes } = props;
|
||||||
|
|
||||||
|
// use case
|
||||||
|
const [useCaseId, setUseCaseId] = useState("");
|
||||||
|
const [useCaseDetails, setUseCaseDetails] = useState('');
|
||||||
|
const [measurementsCount, setMeasurementsCount] = useState(0);
|
||||||
|
const [lastMeasurementId, setLastMeasurementId] = useState("");
|
||||||
|
const [pinCode, setPinCode] = useState(null);
|
||||||
|
|
||||||
|
// general
|
||||||
|
const [displayText, setDisplayText] = useState(true);
|
||||||
|
const [success, setSuccess] = useState(null);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [connectivityIssue, setConnectivityIssue] = useState(false);
|
||||||
|
|
||||||
|
const { id } = useParams();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const useCaseId = id;
|
||||||
|
let body = {
|
||||||
|
pinCode: pinCode
|
||||||
|
}
|
||||||
|
|
||||||
|
body.pinCode = new URLSearchParams(location).get("pinCode")
|
||||||
|
if (!body.pinCode) {
|
||||||
|
body.pinCode = prompt("Please provide the secure pincode of this use case to access the measurement area")
|
||||||
|
}
|
||||||
|
|
||||||
|
setPinCode(body.pinCode)
|
||||||
|
|
||||||
|
// check if correct pin has been provided
|
||||||
|
custom_fetch('post', '/useCases/' + useCaseId + '/authorize', body)
|
||||||
|
.then(response => {
|
||||||
|
// if succesfully set useCase ID and load cases, otherwise show error
|
||||||
|
setUseCaseId(useCaseId);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
setError({ message: "Wrong pinCode provide there for no access granted" })
|
||||||
|
})
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getUseCase()
|
||||||
|
}, [useCaseId]);
|
||||||
|
|
||||||
|
|
||||||
|
const custom_fetch = async (method, endpoint, body, surpressError) => {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API}/api${endpoint}`, {
|
||||||
|
method,
|
||||||
|
body: body && JSON.stringify(body),
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
accept: 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
|
||||||
|
if (response.ok && (response.status === 201 || response.status === 200)) {
|
||||||
|
return await response.json();
|
||||||
|
} else {
|
||||||
|
setError({ message: "Error when communicating with backend: " + response.statusText })
|
||||||
|
|
||||||
|
throw new Error("Error communicating with backend")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// used to surpress the error notifcation
|
||||||
|
if (!surpressError) {
|
||||||
|
setError(error)
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// recursive extension of the fetch method
|
||||||
|
// allows to reexecute failed fetch calls until they succeded
|
||||||
|
const fetch_retry = async (method, endpoint, body) => {
|
||||||
|
let error = null
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await custom_fetch(method, endpoint, body, true)
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
error = err
|
||||||
|
// retry after some wait period, and update state if not already done
|
||||||
|
if (!connectivityIssue) {
|
||||||
|
setConnectivityIssue(true)
|
||||||
|
setError({ message: "Error when communicating with backend. We are continuously trying it and will inform you as soon as the connection has ben reestablished. The measurements are still being saved locally and synchronized as soon as connection is present again." })
|
||||||
|
}
|
||||||
|
|
||||||
|
await sleep(REXECUTION_TIMEOUT)
|
||||||
|
return fetch_retry(method, endpoint, body)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
// if err
|
||||||
|
if (!error && connectivityIssue) {
|
||||||
|
setConnectivityIssue(false)
|
||||||
|
setSuccess("Connection established again. Now syncing your measurements. Check the above measurement counter.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// function which sleeps some defined milliseconds
|
||||||
|
const sleep = (ms) => {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms))
|
||||||
|
}
|
||||||
|
|
||||||
|
const getMeasurementsCount = async () => {
|
||||||
|
let measurementsCount = []
|
||||||
|
if (useCaseId) measurementsCount = await custom_fetch('get', '/useCases/' + useCaseId + '/measurements/count')
|
||||||
|
|
||||||
|
setMeasurementsCount(measurementsCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
const getUseCase = async () => {
|
||||||
|
setUseCaseDetails((await custom_fetch('get', '/useCases/' + useCaseId)) || [])
|
||||||
|
getMeasurementsCount()
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteLastMeasurement = async () => {
|
||||||
|
//only allowed to delete the last measurement by themselves
|
||||||
|
if (lastMeasurementId) {
|
||||||
|
await custom_fetch("DELETE", "/measurements/" + lastMeasurementId)
|
||||||
|
|
||||||
|
getMeasurementsCount()
|
||||||
|
setLastMeasurementId("")
|
||||||
|
setSuccess("Your last measurement was successfully deleted")
|
||||||
|
} else {
|
||||||
|
setError({ message: "You can only delete your own last measurement, please execute a measurement first" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveMeasurement = async (groupName, buttonValue) => {
|
||||||
|
const postData = {
|
||||||
|
"useCase": useCaseId,
|
||||||
|
"groupName": groupName,
|
||||||
|
"timestamp": Date.now(), // set measurement time in frontend
|
||||||
|
"value": buttonValue
|
||||||
|
}
|
||||||
|
|
||||||
|
// post data as long till it is successfull
|
||||||
|
await fetch_retry('post', `/measurements/`, postData)
|
||||||
|
.then(response => {
|
||||||
|
setLastMeasurementId(response.id)
|
||||||
|
getMeasurementsCount()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy the direct link to a use case measurement to the clipboard
|
||||||
|
// the link includes the PIN code
|
||||||
|
const shareLink = () => {
|
||||||
|
let url = window.location.href + "?pinCode=" + pinCode
|
||||||
|
navigator.clipboard.writeText(url)
|
||||||
|
|
||||||
|
setSuccess("Direct link copied to clipboard")
|
||||||
|
}
|
||||||
|
|
||||||
|
// toogle if text should be displayed or not
|
||||||
|
const toogleIconView = () => {
|
||||||
|
setDisplayText(!displayText)
|
||||||
|
}
|
||||||
|
|
||||||
|
// toogle full screen
|
||||||
|
const toggleFullscreen = () => {
|
||||||
|
let elem = document.querySelector("body");
|
||||||
|
|
||||||
|
if (!document.fullscreenElement) {
|
||||||
|
elem.requestFullscreen().catch(err => {
|
||||||
|
alert(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
document.exitFullscreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<Typography className={classes.title} variant="h6">Measurements {useCaseDetails.name} </Typography>
|
||||||
|
|
||||||
|
{ /* action items */}
|
||||||
|
<ActionItems
|
||||||
|
toggleFullscreen={toggleFullscreen}
|
||||||
|
toogleIconView={toogleIconView}
|
||||||
|
shareLink={shareLink}
|
||||||
|
deleteLastMeasurement={deleteLastMeasurement}
|
||||||
|
measurementsCount={measurementsCount}
|
||||||
|
useCaseId={useCaseId}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{useCaseDetails && useCaseDetails.measurementOptions && useCaseDetails.measurementOptions.length > 0 ? (
|
||||||
|
// measurements present
|
||||||
|
|
||||||
|
useCaseDetails.measurementOptions.map(function (groupElement, groupIndex, groupArray) {
|
||||||
|
// iteration for groups
|
||||||
|
|
||||||
|
let buttons = groupElement.options.map(function (optionElement, opionIndex, optionsArray) {
|
||||||
|
// iteration for buttons
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid item xs key={opionIndex}>
|
||||||
|
<MeasurementButtons
|
||||||
|
onClick={saveMeasurement}
|
||||||
|
key={`${opionIndex}-${optionElement.name}`}
|
||||||
|
groupName={groupElement.name}
|
||||||
|
buttonValue={optionElement.name}
|
||||||
|
length={optionsArray.length}
|
||||||
|
groupLength={groupArray.length}
|
||||||
|
displayText={displayText}
|
||||||
|
icon={optionElement.icon}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classes.root} key={`${groupIndex}buttonList`}>
|
||||||
|
<Typography className={classes.measurementGroupTitle}>{groupElement.name}</Typography>
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
{buttons}
|
||||||
|
</Grid>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
) : (
|
||||||
|
// no measurements could be found
|
||||||
|
!loading && (
|
||||||
|
<Typography variant="subtitle1">No measurements have been taken so far</Typography>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
|
||||||
|
{ /* Flag based display of error snackbar */}
|
||||||
|
{error && (
|
||||||
|
<ErrorSnackbar
|
||||||
|
onClose={() => setError(null)}
|
||||||
|
message={error.message}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{ /* Flag based display of info snackbar */}
|
||||||
|
{success && (
|
||||||
|
<InfoSnackbar
|
||||||
|
onClose={() => setSuccess(null)}
|
||||||
|
message={success}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withStyles(styles)(UseCaseMeasurement);
|
141
counter_kand/frontend/src/serviceWorker.js
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
// This optional code is used to register a service worker.
|
||||||
|
// register() is not called by default.
|
||||||
|
|
||||||
|
// This lets the app load faster on subsequent visits in production, and gives
|
||||||
|
// it offline capabilities. However, it also means that developers (and users)
|
||||||
|
// will only see deployed updates on subsequent visits to a page, after all the
|
||||||
|
// existing tabs open on the page have been closed, since previously cached
|
||||||
|
// resources are updated in the background.
|
||||||
|
|
||||||
|
// To learn more about the benefits of this model and instructions on how to
|
||||||
|
// opt-in, read https://bit.ly/CRA-PWA
|
||||||
|
|
||||||
|
const isLocalhost = Boolean(
|
||||||
|
window.location.hostname === 'localhost' ||
|
||||||
|
// [::1] is the IPv6 localhost address.
|
||||||
|
window.location.hostname === '[::1]' ||
|
||||||
|
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||||
|
window.location.hostname.match(
|
||||||
|
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export function register(config) {
|
||||||
|
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||||
|
// The URL constructor is available in all browsers that support SW.
|
||||||
|
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||||
|
if (publicUrl.origin !== window.location.origin) {
|
||||||
|
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||||
|
// from what our page is served on. This might happen if a CDN is used to
|
||||||
|
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||||
|
|
||||||
|
if (isLocalhost) {
|
||||||
|
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||||
|
checkValidServiceWorker(swUrl, config);
|
||||||
|
|
||||||
|
// Add some additional logging to localhost, pointing developers to the
|
||||||
|
// service worker/PWA documentation.
|
||||||
|
navigator.serviceWorker.ready.then(() => {
|
||||||
|
console.log(
|
||||||
|
'This web app is being served cache-first by a service ' +
|
||||||
|
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Is not localhost. Just register service worker
|
||||||
|
registerValidSW(swUrl, config);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerValidSW(swUrl, config) {
|
||||||
|
navigator.serviceWorker
|
||||||
|
.register(swUrl)
|
||||||
|
.then(registration => {
|
||||||
|
registration.onupdatefound = () => {
|
||||||
|
const installingWorker = registration.installing;
|
||||||
|
if (installingWorker == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
installingWorker.onstatechange = () => {
|
||||||
|
if (installingWorker.state === 'installed') {
|
||||||
|
if (navigator.serviceWorker.controller) {
|
||||||
|
// At this point, the updated precached content has been fetched,
|
||||||
|
// but the previous service worker will still serve the older
|
||||||
|
// content until all client tabs are closed.
|
||||||
|
console.log(
|
||||||
|
'New content is available and will be used when all ' +
|
||||||
|
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Execute callback
|
||||||
|
if (config && config.onUpdate) {
|
||||||
|
config.onUpdate(registration);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// At this point, everything has been precached.
|
||||||
|
// It's the perfect time to display a
|
||||||
|
// "Content is cached for offline use." message.
|
||||||
|
console.log('Content is cached for offline use.');
|
||||||
|
|
||||||
|
// Execute callback
|
||||||
|
if (config && config.onSuccess) {
|
||||||
|
config.onSuccess(registration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error during service worker registration:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkValidServiceWorker(swUrl, config) {
|
||||||
|
// Check if the service worker can be found. If it can't reload the page.
|
||||||
|
fetch(swUrl, {
|
||||||
|
headers: { 'Service-Worker': 'script' },
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
// Ensure service worker exists, and that we really are getting a JS file.
|
||||||
|
const contentType = response.headers.get('content-type');
|
||||||
|
if (
|
||||||
|
response.status === 404 ||
|
||||||
|
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||||
|
) {
|
||||||
|
// No service worker found. Probably a different app. Reload the page.
|
||||||
|
navigator.serviceWorker.ready.then(registration => {
|
||||||
|
registration.unregister().then(() => {
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Service worker found. Proceed as normal.
|
||||||
|
registerValidSW(swUrl, config);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
console.log(
|
||||||
|
'No internet connection found. App is running in offline mode.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unregister() {
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
navigator.serviceWorker.ready
|
||||||
|
.then(registration => {
|
||||||
|
registration.unregister();
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
5
counter_kand/frontend/src/setupTests.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||||
|
// allows you to do things like:
|
||||||
|
// expect(element).toHaveTextContent(/react/i)
|
||||||
|
// learn more: https://github.com/testing-library/jest-dom
|
||||||
|
import '@testing-library/jest-dom/extend-expect';
|
25
deploy.sh
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
GITHUB_USERNAME="your_github_username"
|
||||||
|
VERSION="v1"
|
||||||
|
if [ "$GITHUB_USERNAME" == "your_github_username" ]; then
|
||||||
|
echo "you buffoon change your github username in the file."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
replace_placeholders() {
|
||||||
|
sed -i "s|ghcr.io/informaticker/zli-counter-frontend:v1|ghcr.io/${GITHUB_USERNAME}/zli-counter-frontend:${VERSION}|g" deployment/frontend.yaml
|
||||||
|
sed -i "s|ghcr.io/informaticker/zli-counter-backend:v1|ghcr.io/${GITHUB_USERNAME}/zli-counter-backend:${VERSION}|g" deployment/backend.yaml
|
||||||
|
}
|
||||||
|
docker build -t ghcr.io/${GITHUB_USERNAME}/zli-counter-backend:${VERSION} counter_kand/backend
|
||||||
|
docker build -t ghcr.io/${GITHUB_USERNAME}/zli-counter-frontend:${VERSION} counter_kand/frontend
|
||||||
|
docker push ghcr.io/${GITHUB_USERNAME}/zli-counter-backend:${VERSION}
|
||||||
|
docker push ghcr.io/${GITHUB_USERNAME}/zli-counter-frontend:${VERSION}
|
||||||
|
replace_placeholders
|
||||||
|
|
||||||
|
oc apply -f deployment/configmap.yaml
|
||||||
|
oc apply -f deployment/secrets.yaml
|
||||||
|
oc apply -f deployment/database.yaml
|
||||||
|
oc apply -f deployment/backend.yaml
|
||||||
|
oc apply -f deployment/frontend.yaml
|
||||||
|
|
||||||
|
echo "Deployment completed successfully! ^w^"
|
76
deployment/backend.yaml
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: counter-backend
|
||||||
|
labels:
|
||||||
|
app: counter-backend
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: counter-backend
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: counter-backend
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: counter-backend
|
||||||
|
image: ghcr.io/informaticker/zli-counter-backend:v1
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
env:
|
||||||
|
- name: DB_USER
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: counter-database
|
||||||
|
key: database-user
|
||||||
|
- name: DB_NAME
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: counter-database
|
||||||
|
key: database-name
|
||||||
|
- name: DB_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: counter-database
|
||||||
|
key: database-password
|
||||||
|
- name: DB_HOST
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: counter-config
|
||||||
|
key: DB_HOST
|
||||||
|
- name: PASSPHRASE
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: counter-secret
|
||||||
|
key: PASSPHRASE
|
||||||
|
- name: npm_config_cache
|
||||||
|
value: ./.npm-cache
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: counter-backend
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: counter-backend
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 8080
|
||||||
|
targetPort: 8080
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: route.openshift.io/v1
|
||||||
|
kind: Route
|
||||||
|
metadata:
|
||||||
|
name: counter-backend
|
||||||
|
spec:
|
||||||
|
to:
|
||||||
|
kind: Service
|
||||||
|
name: counter-backend
|
||||||
|
tls:
|
||||||
|
termination: edge
|
||||||
|
insecureEdgeTerminationPolicy: Redirect
|
8
deployment/configmap.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: counter-config
|
||||||
|
data:
|
||||||
|
DB_HOST: counter-database
|
||||||
|
BACKEND_URL: https://counter-backend-computerficker-dev.apps.sandbox-m3.1530.p1.openshiftapps.com
|
50
deployment/database.yaml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
kind: Deployment
|
||||||
|
apiVersion: apps/v1
|
||||||
|
metadata:
|
||||||
|
name: counter-database
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: counter-database
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: counter-database
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: counter-database
|
||||||
|
image: quay.io/centos7/postgresql-10-centos7:20221109
|
||||||
|
imagePullPolicy: Always
|
||||||
|
ports:
|
||||||
|
- containerPort: 5432
|
||||||
|
env:
|
||||||
|
- name: POSTGRESQL_USER
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: counter-database
|
||||||
|
key: database-user
|
||||||
|
- name: POSTGRESQL_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: counter-database
|
||||||
|
key: database-password
|
||||||
|
- name: POSTGRESQL_DATABASE
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: counter-database
|
||||||
|
key: database-name
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: counter-database
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: counter-database
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 5432
|
||||||
|
targetPort: 5432
|
57
deployment/frontend.yaml
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: counter-frontend
|
||||||
|
labels:
|
||||||
|
app: counter-frontend
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: counter-frontend
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: counter-frontend
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: counter-frontend
|
||||||
|
image: ghcr.io/informaticker/zli-counter-frontend:v1
|
||||||
|
ports:
|
||||||
|
- containerPort: 3000
|
||||||
|
env:
|
||||||
|
- name: BACKEND_URL
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: counter-config
|
||||||
|
key: BACKEND_URL
|
||||||
|
- name: npm_config_cache
|
||||||
|
value: ./.npm-cache
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: counter-frontend
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: counter-frontend
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 3000
|
||||||
|
targetPort: 3000
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: route.openshift.io/v1
|
||||||
|
kind: Route
|
||||||
|
metadata:
|
||||||
|
name: counter-frontend
|
||||||
|
spec:
|
||||||
|
to:
|
||||||
|
kind: Service
|
||||||
|
name: counter-frontend
|
||||||
|
tls:
|
||||||
|
termination: edge
|
||||||
|
insecureEdgeTerminationPolicy: Redirect
|
||||||
|
|
18
deployment/secrets.yaml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: counter-database
|
||||||
|
type: Opaque
|
||||||
|
stringData:
|
||||||
|
database-name: counter_db
|
||||||
|
database-user: counter_user
|
||||||
|
database-password: counter_password_bPqNMg33
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: counter-secret
|
||||||
|
type: Opaque
|
||||||
|
stringData:
|
||||||
|
PASSPHRASE: supersecurephrase
|