Compare commits
1 Commits
master
...
integratio
Author | SHA1 | Date |
---|---|---|
Josha von Gizycki | 0166b4491a | 5 years ago |
@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if lein test; then
|
|
||||||
echo "testing successul";
|
|
||||||
else
|
|
||||||
echo "tests failed";
|
|
||||||
sendmail -s "wanijo build failed" mail@joshavg.de < $ALFRED_LOG_FILE;
|
|
||||||
fi;
|
|
@ -1,675 +0,0 @@
|
|||||||
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>.
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
|||||||
# Wanijo
|
|
||||||
|
|
||||||
> (Toki Pona)
|
|
||||||
> Wan: One, a, unite, make one
|
|
||||||
> Ijo: thing, something, object
|
|
||||||
> Wanijo: Unite things
|
|
||||||
|
|
||||||
## How to develop
|
|
||||||
|
|
||||||
You'll need:
|
|
||||||
|
|
||||||
- JDK >= 8
|
|
||||||
- Leiningen >= 2.9
|
|
||||||
|
|
||||||
### First time launch with fresh a database
|
|
||||||
|
|
||||||
- start a neo4j database with `lein neo4j`
|
|
||||||
- start a repl with `lein repl` or similar
|
|
||||||
- import `wanijo.infra.repl`
|
|
||||||
- if you use leiningen for launching the repl, this will be your init-ns
|
|
||||||
- run `wanijo.infra.repl/create-user!` using the desired username and password as parameters to create an application user
|
|
||||||
- run `wanijo.infra.repl/run-migrations!` to create desireable database constraints and structures
|
|
||||||
|
|
||||||
### Launch the application server
|
|
||||||
|
|
||||||
- start a repl
|
|
||||||
- import `wanijo.infra.repl`
|
|
||||||
- run `wanijo.infra.repl/dev-server!`
|
|
||||||
- the application is available on port `8080`
|
|
||||||
|
|
||||||
## Launch as a standalone
|
|
||||||
|
|
||||||
- build the uberjar via `lein uberjar`
|
|
||||||
- start your neo4j database, preferably **not** via `lein neo4j`
|
|
||||||
- use the environment variables `NEO4J_PORT`, `NEO4J_HOST`, `NEO4J_USER` and `NEO4J_PASS` to control how wanijo connects to the database
|
|
||||||
- start the jar file via `java -jar [jar-file]-standalone.jar`
|
|
||||||
- if this is the first start with a fresh database, connect to the nREPL as described in the chapter "nREPL" and run the commands described in "First time launch with a fresh database"
|
|
||||||
|
|
||||||
### nREPL
|
|
||||||
|
|
||||||
When started via its `main` method, as is the uberjar case, an nREPL server is started with it. The default port is `7888`, but this can be configured via the `NREPL_PORT` environment variable.
|
|
||||||
|
|
||||||
To connect via the command line, use the following command:
|
|
||||||
|
|
||||||
```
|
|
||||||
clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.7.0"}}}' -m nrepl.cmdline --connect --host host --port port
|
|
||||||
```
|
|
||||||
|
|
||||||
### "Architecture"
|
|
||||||
|
|
||||||
> Structure your application as it seems to fit your needs. Then call it architecture and pat yourself on the shoulder. You've achieved something!
|
|
||||||
|
|
||||||
The first level of structure are the building blocks of the domain, e.g. `instance`, `schema`. Inside these namespaces you'll find namespaces for each technical need: routing, database access, domain rules etc.
|
|
||||||
|
|
||||||
`wanijo.handler` collects all routes and passes them to ring.
|
|
||||||
|
|
||||||
`wanijo.infra` contains the namespaces needed for technical code that do not belong to any domain, like database access, routing or similars.
|
|
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"type": "application",
|
||||||
|
"source-directories": [
|
||||||
|
"src/frontend"
|
||||||
|
],
|
||||||
|
"elm-version": "0.19.0",
|
||||||
|
"dependencies": {
|
||||||
|
"direct": {
|
||||||
|
"elm/browser": "1.0.1",
|
||||||
|
"elm/core": "1.0.2",
|
||||||
|
"elm/html": "1.0.0"
|
||||||
|
},
|
||||||
|
"indirect": {
|
||||||
|
"elm/json": "1.1.3",
|
||||||
|
"elm/time": "1.0.0",
|
||||||
|
"elm/url": "1.0.0",
|
||||||
|
"elm/virtual-dom": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test-dependencies": {
|
||||||
|
"direct": {},
|
||||||
|
"indirect": {}
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 6.0 KiB |
@ -0,0 +1,24 @@
|
|||||||
|
.devbar {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
font-family: monospace;
|
||||||
|
background-color: #ccc;
|
||||||
|
|
||||||
|
ol {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
li {
|
||||||
|
padding: .5rem;
|
||||||
|
border: 1px solid black;
|
||||||
|
margin: .5rem;
|
||||||
|
|
||||||
|
pre {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
.devbar {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
font-family: monospace;
|
||||||
|
background-color: #ccc;
|
||||||
|
}
|
||||||
|
.devbar ol {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.devbar ol li {
|
||||||
|
padding: .5rem;
|
||||||
|
border: 1px solid black;
|
||||||
|
margin: .5rem;
|
||||||
|
}
|
||||||
|
.devbar ol li pre {
|
||||||
|
margin: 0;
|
||||||
|
}
|
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.4 KiB |
@ -1,82 +0,0 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function () {
|
|
||||||
const canvas = document.querySelector('.vis-canvas')
|
|
||||||
|
|
||||||
const nodes = new vis.DataSet([])
|
|
||||||
const edges = new vis.DataSet([])
|
|
||||||
|
|
||||||
const network = new vis.Network(canvas, {
|
|
||||||
nodes: nodes,
|
|
||||||
edges: edges
|
|
||||||
}, {
|
|
||||||
manipulation: true
|
|
||||||
})
|
|
||||||
|
|
||||||
const instanceLabel = (inst, schema) => `${inst.name}\n${schema.name}`
|
|
||||||
|
|
||||||
const addNode = (toAdd) => {
|
|
||||||
try {
|
|
||||||
nodes.add({
|
|
||||||
id: toAdd.uuid,
|
|
||||||
label: instanceLabel(toAdd, toAdd.schema)
|
|
||||||
})
|
|
||||||
} catch(e) {
|
|
||||||
console.debug(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const addOutEdges = (fromId, toAdd) => {
|
|
||||||
toAdd.forEach((inst) => {
|
|
||||||
try {
|
|
||||||
edges.add({
|
|
||||||
from: fromId,
|
|
||||||
to: inst.uuid,
|
|
||||||
label: inst['link-name'],
|
|
||||||
arrows: {
|
|
||||||
to: {enabled: true}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
console.debug(e)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const addLinkedNodes = (toAdd) => {
|
|
||||||
toAdd.forEach((inst) => {
|
|
||||||
try {
|
|
||||||
console.debug(inst.name)
|
|
||||||
nodes.add({
|
|
||||||
id: inst.uuid,
|
|
||||||
label: instanceLabel(inst, inst.schema)
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
console.debug(e)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const addInstance = (instance) => {
|
|
||||||
addNode(instance)
|
|
||||||
addLinkedNodes(instance['links-out'])
|
|
||||||
addOutEdges(instance.uuid, instance['links-out'])
|
|
||||||
}
|
|
||||||
|
|
||||||
fetch(canvas.getAttribute('data-instance-url'))
|
|
||||||
.then((resp) => resp.json())
|
|
||||||
.then((json) => {
|
|
||||||
addInstance(json)
|
|
||||||
})
|
|
||||||
|
|
||||||
const searchForm = document.querySelector('.search')
|
|
||||||
const searchUrl = searchForm.getAttribute('action')
|
|
||||||
searchForm.addEventListener('submit', (event) => {
|
|
||||||
event.preventDefault()
|
|
||||||
const term = searchForm.querySelector('[name=term]').value
|
|
||||||
fetch(searchUrl + encodeURIComponent(term))
|
|
||||||
.then((resp) => resp.json())
|
|
||||||
.then((json) => {
|
|
||||||
console.debug(json)
|
|
||||||
json.forEach((inst) => {
|
|
||||||
addInstance(inst)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,168 +0,0 @@
|
|||||||
(ns formulare.core
|
|
||||||
(:require [formulare.theme :as theme]
|
|
||||||
[clojure.spec.alpha :as spec]
|
|
||||||
[clojure.spec.test.alpha :as spectest]
|
|
||||||
[hiccup
|
|
||||||
[form :as hform]
|
|
||||||
[core :as hcore]]
|
|
||||||
[ring.util.anti-forgery :refer [anti-forgery-field]]))
|
|
||||||
|
|
||||||
(spec/def ::label string?)
|
|
||||||
(spec/def ::required boolean?)
|
|
||||||
(spec/def ::spec
|
|
||||||
(spec/or :registered-spec keyword?
|
|
||||||
:predicate ifn?))
|
|
||||||
(spec/def ::options
|
|
||||||
(spec/or :empty empty?
|
|
||||||
:options (spec/coll-of (spec/tuple string? string?))))
|
|
||||||
(spec/def ::widget
|
|
||||||
#{:input :select :checkbox :textarea :mselect :hidden :file})
|
|
||||||
(spec/def ::from-req ifn?)
|
|
||||||
(spec/def ::to-form ::from-req)
|
|
||||||
(spec/def ::attrs (spec/map-of keyword? (fn [_] true)))
|
|
||||||
(spec/def ::field
|
|
||||||
(spec/keys :opt-un [::label
|
|
||||||
::options
|
|
||||||
::widget
|
|
||||||
::from-req
|
|
||||||
::to-form
|
|
||||||
::required
|
|
||||||
::spec
|
|
||||||
::attrs]))
|
|
||||||
(spec/def ::fields
|
|
||||||
(spec/map-of keyword? ::field))
|
|
||||||
(spec/def ::form-specs
|
|
||||||
(spec/coll-of ::spec))
|
|
||||||
(spec/def ::form
|
|
||||||
(spec/keys :req-un [::fields]
|
|
||||||
:opt-un [::form-specs]))
|
|
||||||
|
|
||||||
(defn form-data [form-def req]
|
|
||||||
(reduce (fn [coll [id field]]
|
|
||||||
(let [value (get-in req [:params id])]
|
|
||||||
(assoc coll
|
|
||||||
id
|
|
||||||
(if-let [from-req (:from-req field)]
|
|
||||||
(from-req value)
|
|
||||||
value))))
|
|
||||||
{}
|
|
||||||
(:fields form-def)))
|
|
||||||
|
|
||||||
(spec/fdef form-data
|
|
||||||
:args (spec/cat :form-def ::form :req map?)
|
|
||||||
:ret map?)
|
|
||||||
(spectest/instrument `form-data)
|
|
||||||
|
|
||||||
(defn form-specs-valid? [form-def req]
|
|
||||||
(reduce (fn [valid? form-spec]
|
|
||||||
(if (spec/valid? form-spec req)
|
|
||||||
true
|
|
||||||
(reduced false)))
|
|
||||||
true
|
|
||||||
(:form-specs form-def)))
|
|
||||||
|
|
||||||
(defn field-specs-valid? [form-def req]
|
|
||||||
(reduce-kv
|
|
||||||
(fn [result field field-def]
|
|
||||||
(if-let [field-spec (:spec field-def)]
|
|
||||||
(if (spec/valid? field-spec (get-in req [:params field]))
|
|
||||||
true
|
|
||||||
(reduced false))
|
|
||||||
result))
|
|
||||||
true
|
|
||||||
(:fields form-def)))
|
|
||||||
|
|
||||||
(defn valid? [form-def req]
|
|
||||||
(let [data (form-data form-def req)]
|
|
||||||
(and (field-specs-valid? form-def req)
|
|
||||||
(form-specs-valid? form-def req))))
|
|
||||||
|
|
||||||
(spec/fdef valid?
|
|
||||||
:args (spec/cat :form-def ::form :req map?)
|
|
||||||
:ret map?)
|
|
||||||
(spectest/instrument `valid?)
|
|
||||||
|
|
||||||
(def ^:dynamic *row-theme* theme/row)
|
|
||||||
(def ^:dynamic *widget-error-theme* theme/widget-error)
|
|
||||||
(def ^:dynamic *form-error-theme* theme/form-error)
|
|
||||||
(def ^:dynamic *label-theme* theme/label)
|
|
||||||
(def ^:dynamic *input-widget-theme* theme/input-widget)
|
|
||||||
(def ^:dynamic *checkbox-widget-theme* theme/checkbox-widget)
|
|
||||||
(def ^:dynamic *textarea-widget-theme* theme/textarea-widget)
|
|
||||||
(def ^:dynamic *select-widget-theme* theme/select-widget)
|
|
||||||
(def ^:dynamic *mselect-widget-theme* theme/multiselect-widget)
|
|
||||||
(def ^:dynamic *hidden-widget-theme* theme/hidden-widget)
|
|
||||||
(def ^:dynamic *file-widget-theme* theme/file-widget)
|
|
||||||
|
|
||||||
(defn widget-markup [values req validate? [id def]]
|
|
||||||
(let [{:keys [spec widget to-form]} def
|
|
||||||
value ((or to-form identity) (id values))
|
|
||||||
req-value (get-in req [:params id])
|
|
||||||
renderer (case widget
|
|
||||||
:checkbox *checkbox-widget-theme*
|
|
||||||
:textarea *textarea-widget-theme*
|
|
||||||
:select *select-widget-theme*
|
|
||||||
:mselect *mselect-widget-theme*
|
|
||||||
:hidden *hidden-widget-theme*
|
|
||||||
:file *file-widget-theme*
|
|
||||||
*input-widget-theme*)]
|
|
||||||
(*row-theme* (when (and validate?
|
|
||||||
spec
|
|
||||||
(not (spec/valid? spec req-value)))
|
|
||||||
(*widget-error-theme* id def req-value))
|
|
||||||
(*label-theme* id def)
|
|
||||||
(renderer id def (if validate? req-value value)))))
|
|
||||||
|
|
||||||
(defn form-hash [form-def values]
|
|
||||||
(str (hash [form-def values])))
|
|
||||||
|
|
||||||
(defn validate? [form-def values req]
|
|
||||||
(= (form-hash form-def values)
|
|
||||||
(get-in req [:params :__form-hash])))
|
|
||||||
|
|
||||||
(defn render-widgets
|
|
||||||
([form-def values req]
|
|
||||||
(render-widgets form-def values req
|
|
||||||
{:render-anti-forgery-field? true}))
|
|
||||||
([form-def values req {raff? :render-anti-forgery-field?}]
|
|
||||||
(let [validate? (validate? form-def values req)
|
|
||||||
form-errors (when (and validate?
|
|
||||||
(not (form-specs-valid? form-def
|
|
||||||
req)))
|
|
||||||
(*form-error-theme* form-def req))
|
|
||||||
widget-mapper (partial widget-markup values req validate?)
|
|
||||||
defined-widgets (map widget-mapper (:fields form-def))
|
|
||||||
hash-field (hform/hidden-field "__form-hash"
|
|
||||||
(form-hash form-def values))
|
|
||||||
all-widgets (conj defined-widgets
|
|
||||||
hash-field)
|
|
||||||
all-widgets (if raff?
|
|
||||||
(conj all-widgets (anti-forgery-field))
|
|
||||||
all-widgets)]
|
|
||||||
(if form-errors
|
|
||||||
(concat (if (sequential? form-errors)
|
|
||||||
form-errors
|
|
||||||
[form-errors])
|
|
||||||
all-widgets)
|
|
||||||
all-widgets))))
|
|
||||||
|
|
||||||
(spec/def ::render-anti-forgery-field?
|
|
||||||
#(boolean? (boolean %)))
|
|
||||||
|
|
||||||
(spec/def ::options-map
|
|
||||||
(spec/keys :req-un
|
|
||||||
[::render-anti-forgery-field?]))
|
|
||||||
|
|
||||||
(spec/fdef render-widgets
|
|
||||||
:args (spec/or :three-params
|
|
||||||
(spec/cat :form-def ::form
|
|
||||||
:values (spec/or :no-values nil?
|
|
||||||
:values map?)
|
|
||||||
:req map?)
|
|
||||||
:four-params
|
|
||||||
(spec/cat :form-def ::form
|
|
||||||
:values (spec/or :no-values nil?
|
|
||||||
:values map?)
|
|
||||||
:req map?
|
|
||||||
:options ::options-map)))
|
|
||||||
(spectest/instrument `render-widgets)
|
|
@ -1,85 +0,0 @@
|
|||||||
(ns formulare.theme
|
|
||||||
(:require [clojure.spec.alpha :as spec]
|
|
||||||
[hiccup
|
|
||||||
[form :as hform]
|
|
||||||
[core :as hcore]]))
|
|
||||||
|
|
||||||
(defn row [& content] content)
|
|
||||||
|
|
||||||
(defn err-msg [content]
|
|
||||||
[:section.flash--error
|
|
||||||
[:h2.flash__heading--error "Warning"]
|
|
||||||
content])
|
|
||||||
|
|
||||||
(defn widget-error [id field-def field-value]
|
|
||||||
(err-msg
|
|
||||||
(map
|
|
||||||
(fn [prob]
|
|
||||||
[:p
|
|
||||||
"Field "
|
|
||||||
[:span.flash__field
|
|
||||||
(hcore/h (:label field-def))]
|
|
||||||
" must comply to "
|
|
||||||
[:span.flash__pred
|
|
||||||
(hcore/h (:pred prob))]])
|
|
||||||
(:clojure.spec.alpha/problems
|
|
||||||
(spec/explain-data (:spec field-def)
|
|
||||||
field-value)))))
|
|
||||||
|
|
||||||
(defn form-error [form-def req]
|
|
||||||
(for [prob (mapcat #(:clojure.spec.alpha/problems
|
|
||||||
(spec/explain-data % req))
|
|
||||||
(:form-specs form-def))]
|
|
||||||
(err-msg [:p "The form must comply to "
|
|
||||||
(hcore/h (:pred prob))])))
|
|
||||||
|
|
||||||
(defn label [field-id field-def]
|
|
||||||
(when-not (= :hidden (:widget field-def))
|
|
||||||
(hform/label field-id (:label field-def))))
|
|
||||||
|
|
||||||
(defn input-widget [id def value]
|
|
||||||
(hform/text-field (merge {:required (or (:required def) false)}
|
|
||||||
(:attrs def))
|
|
||||||
id
|
|
||||||
value))
|
|
||||||
|
|
||||||
(defn checkbox-widget [id def value]
|
|
||||||
(hform/check-box id
|
|
||||||
(and (some? value)
|
|
||||||
(not= 0 value))
|
|
||||||
value))
|
|
||||||
|
|
||||||
(defn textarea-widget [id def value]
|
|
||||||
(hform/text-area (merge {:required (or (:required def) false)}
|
|
||||||
(:attrs def))
|
|
||||||
id
|
|
||||||
value))
|
|
||||||
|
|
||||||
(defn select-widget [id def value]
|
|
||||||
(hform/drop-down id
|
|
||||||
(:options def)
|
|
||||||
value))
|
|
||||||
|
|
||||||
(defn multiselect-widget [id def value]
|
|
||||||
[:select (merge {:multiple "multiple"
|
|
||||||
:size (:size def 5)
|
|
||||||
:name (name id)
|
|
||||||
:id (name id)}
|
|
||||||
(:attrs def))
|
|
||||||
(for [option (:options def)]
|
|
||||||
[:option {:value (second option)
|
|
||||||
:selected (some? (some (partial = (second option))
|
|
||||||
value))}
|
|
||||||
(hcore/h (first option))])])
|
|
||||||
|
|
||||||
(comment
|
|
||||||
(multiselect-widget :id {:options [["<>" "key"]]} {}))
|
|
||||||
|
|
||||||
(defn hidden-widget [id _ value]
|
|
||||||
(hform/hidden-field id value))
|
|
||||||
|
|
||||||
(defn file-widget [id def value]
|
|
||||||
[:input {:type :file
|
|
||||||
:name id
|
|
||||||
:required (or (:required def) false)
|
|
||||||
:value value}])
|
|
@ -0,0 +1,42 @@
|
|||||||
|
module Explore exposing (Msg(..), main, update, view)
|
||||||
|
|
||||||
|
import Browser
|
||||||
|
import Html exposing (Html, button, div, node, text)
|
||||||
|
import Html.Attributes exposing (type_)
|
||||||
|
import Html.Events exposing (onClick)
|
||||||
|
|
||||||
|
|
||||||
|
main =
|
||||||
|
Browser.sandbox { init = 0, update = update, view = view }
|
||||||
|
|
||||||
|
|
||||||
|
type Msg
|
||||||
|
= Increment
|
||||||
|
| Decrement
|
||||||
|
|
||||||
|
|
||||||
|
update msg model =
|
||||||
|
case msg of
|
||||||
|
Increment ->
|
||||||
|
model + 1
|
||||||
|
|
||||||
|
Decrement ->
|
||||||
|
model - 1
|
||||||
|
|
||||||
|
|
||||||
|
withStyle html =
|
||||||
|
div []
|
||||||
|
[ node "style"
|
||||||
|
[ type_ "text/css" ]
|
||||||
|
[ text "@import url(/resources/public/css/app.css)" ]
|
||||||
|
, html
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
view model =
|
||||||
|
div []
|
||||||
|
[ button [ onClick Decrement ] [ text "-" ]
|
||||||
|
, div [] [ text (String.fromInt model) ]
|
||||||
|
, button [ onClick Increment ] [ text "+" ]
|
||||||
|
]
|
||||||
|
|> withStyle
|
@ -1,95 +0,0 @@
|
|||||||
(ns wanijo.attribute.db
|
|
||||||
(:require [wanijo.infra.neo4j :as neo4j]))
|
|
||||||
|
|
||||||
(neo4j/defquery findy-by-schema
|
|
||||||
"MATCH (a:attribute)-->(s:schema)
|
|
||||||
WHERE s.uuid = $uuid
|
|
||||||
RETURN a
|
|
||||||
ORDER BY a.name")
|
|
||||||
(defn find-by-schema! [schema-uuid]
|
|
||||||
(map :a
|
|
||||||
(neo4j/exec-query!
|
|
||||||
findy-by-schema
|
|
||||||
{:uuid schema-uuid})))
|
|
||||||
|
|
||||||
(neo4j/defquery with-name-in-schema
|
|
||||||
"MATCH (a:attribute)-[:of]->(s:schema)
|
|
||||||
WHERE a.name = $name
|
|
||||||
AND s.uuid = $schema_uuid
|
|
||||||
RETURN a")
|
|
||||||
(defn with-name-in-schema! [matching-name schema-uuid]
|
|
||||||
(-> (neo4j/exec-query! with-name-in-schema
|
|
||||||
{:name matching-name
|
|
||||||
:schema_uuid schema-uuid})
|
|
||||||
first
|
|
||||||
:a))
|
|
||||||
|
|
||||||
(neo4j/defquery create-new
|
|
||||||
"MATCH (s:schema {uuid: $schema_uuid}),
|
|
||||||
(u:user {uuid: $user_uuid})
|
|
||||||
CREATE (a:attribute)
|
|
||||||
CREATE (a)-[:created_by]->(u)
|
|
||||||
CREATE (a)-[:of]->(s)
|
|
||||||
SET a.type = $type
|
|
||||||
SET a.name = $name
|
|
||||||
SET a.uuid = $attribute_uuid
|
|
||||||
SET a.required = $required
|
|
||||||
SET a.created_at = $created_at")
|
|
||||||
(defn create-new! [attr schema-uuid user-uuid]
|
|
||||||
(neo4j/exec-query!
|
|
||||||
create-new
|
|
||||||
(assoc attr
|
|
||||||
:user_uuid user-uuid
|
|
||||||
:schema_uuid schema-uuid
|
|
||||||
:attribute_uuid (neo4j/uuid)
|
|
||||||
:created_at (neo4j/now-str))))
|
|
||||||
|
|
||||||
(neo4j/defquery edit
|
|
||||||
"MATCH (a:attribute)
|
|
||||||
WHERE a.uuid = $uuid
|
|
||||||
SET a.type = $type
|
|
||||||
SET a.name = $name
|
|
||||||
SET a.required = $required")
|
|
||||||
(defn edit! [attr]
|
|
||||||
(neo4j/exec-query!
|
|
||||||
edit
|
|
||||||
attr))
|
|
||||||
|
|
||||||
(neo4j/defquery delete-by-uuid
|
|
||||||
"MATCH (a:attribute)-[c]-()
|
|
||||||
WHERE a.uuid = $uuid
|
|
||||||
DELETE c, a")
|
|
||||||
(defn delete-by-uuid! [uuid]
|
|
||||||
(neo4j/exec-query!
|
|
||||||
delete-by-uuid
|
|
||||||
{:uuid uuid}))
|
|
||||||
|
|
||||||
(neo4j/defquery required
|
|
||||||
"MATCH (a:attribute)-[:of]->(s:schema {uuid: $schema_uuid})
|
|
||||||
WHERE a.required = 1
|
|
||||||
RETURN a
|
|
||||||
ORDER BY a.name")
|
|
||||||
(defn required! [schema-uuid]
|
|
||||||
(map :a
|
|
||||||
(neo4j/exec-query! required
|
|
||||||
{:schema_uuid schema-uuid})))
|
|
||||||
|
|
||||||
(neo4j/defquery schema-of
|
|
||||||
"MATCH (a:attribute {uuid:{uuid}})-[:of]->(s:schema)
|
|
||||||
RETURN s")
|
|
||||||
(defn schema-of! [uuid]
|
|
||||||
(->> (neo4j/exec-query! schema-of
|
|
||||||
{:uuid uuid})
|
|
||||||
(map :s)
|
|
||||||
first))
|
|
||||||
|
|
||||||
(neo4j/defquery find-by-instance
|
|
||||||
"MATCH (i:instance {uuid: $instance_uuid}),
|
|
||||||
(i)-[:of]->(s:schema),
|
|
||||||
(a:attribute)-[:of]->(s)
|
|
||||||
RETURN a
|
|
||||||
ORDER BY a.name")
|
|
||||||
(defn find-by-instance! [instance-uuid]
|
|
||||||
(map :a
|
|
||||||
(neo4j/exec-query! find-by-instance
|
|
||||||
{:instance_uuid instance-uuid})))
|
|
@ -1,4 +1,4 @@
|
|||||||
(ns wanijo.infra.common)
|
(ns wanijo.framework.common)
|
||||||
|
|
||||||
(defn in? [coll x]
|
(defn in? [coll x]
|
||||||
(some? (some (partial = x) coll)))
|
(some? (some (partial = x) coll)))
|
@ -0,0 +1,46 @@
|
|||||||
|
(ns wanijo.framework.devmode
|
||||||
|
(:require [hiccup.core :as hcore]
|
||||||
|
[clojure.string :as cljs]))
|
||||||
|
|
||||||
|
(def bar-entries (atom []))
|
||||||
|
|
||||||
|
(defn send-to-bar [msg]
|
||||||
|
(swap! bar-entries #(conj % msg)))
|
||||||
|
|
||||||
|
(defn devmode-on? [req]
|
||||||
|
(let [query-param (get-in req [:query-params "dev"])
|
||||||
|
cookie (get-in req [:cookies "devmode" :value])]
|
||||||
|
(or (= query-param "on")
|
||||||
|
(and (= cookie "1")
|
||||||
|
(not= query-param "off")))))
|
||||||
|
|
||||||
|
(defn devbar [resp]
|
||||||
|
(hcore/html
|
||||||
|
[:section.devbar
|
||||||
|
[:ol
|
||||||
|
(for [entry @bar-entries]
|
||||||
|
[:li [:pre entry]])]]))
|
||||||
|
|
||||||
|
(defn append-devbar [resp]
|
||||||
|
(let [body (:body resp)
|
||||||
|
new-body (cljs/replace
|
||||||
|
body "</body>" (str (devbar resp) "</body>"))]
|
||||||
|
(assoc resp :body new-body)))
|
||||||
|
|
||||||
|
(defn wrap-devmode [handler]
|
||||||
|
(fn [req]
|
||||||
|
(let [on? (devmode-on? req)
|
||||||
|
query-param? (get-in req [:query-params "dev"])
|
||||||
|
new-req (assoc-in req [:session :devmode] on?)
|
||||||
|
resp (handler new-req)
|
||||||
|
new-resp (cond
|
||||||
|
on? (-> resp
|
||||||
|
append-devbar
|
||||||
|
(assoc-in [:cookies :devmode] 1))
|
||||||
|
(some? query-param?) (assoc-in
|
||||||
|
resp
|
||||||
|
[:cookies :devmode]
|
||||||
|
(if on? 1 0))
|
||||||
|
:else resp)]
|
||||||
|
(reset! bar-entries [])
|
||||||
|
new-resp)))
|
@ -0,0 +1,69 @@
|
|||||||
|
(ns wanijo.framework.neo4j
|
||||||
|
(:require [neo4j-clj.core :as db]
|
||||||
|
[wanijo.framework.devmode :as devmode]
|
||||||
|
[clj-time.format :as time-format]
|
||||||
|
[clj-time.local :as time-local]
|
||||||
|
[clojure.spec.alpha :as spec]
|
||||||
|
[clojure.string :as cljs])
|
||||||
|
(:import (java.util UUID)))
|
||||||
|
|
||||||
|
(spec/def ::date-str
|
||||||
|
#(re-matches #"\d{4}\d{2}\d{2}T\d{2}\d{2}\d{2}\.\d{3}Z" %))
|
||||||
|
|
||||||
|
(spec/def ::uuid
|
||||||
|
#(re-matches
|
||||||
|
#"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" %))
|
||||||
|
|
||||||
|
(def ^:dynamic *conn*
|
||||||
|
(let [env #(or (System/getenv %1) %2)
|
||||||
|
port (env "NEO4J_PORT" "7687")
|
||||||
|
host (env "NEO4J_HOST" "localhost")
|
||||||
|
user (env "NEO4J_USER" "neo4j")
|
||||||
|
pass (env "NEO4J_PASS" "b")]
|
||||||
|
(delay (db/connect
|
||||||
|
(str "bolt://" host ":" port)
|
||||||
|
user
|
||||||
|
pass))))
|
||||||
|
|
||||||
|
(defmacro defquery [& args] `(db/defquery ~@args))
|
||||||
|
|
||||||
|
(defn uuid []
|
||||||
|
(str (UUID/randomUUID)))
|
||||||
|
|
||||||
|
(defn butiful-query [qry]
|
||||||
|
(->> qry
|
||||||
|
str
|
||||||
|
cljs/trim-newline
|
||||||
|
cljs/split-lines
|
||||||
|
(map cljs/trim)
|
||||||
|
(filter #(pos? (count %)))
|
||||||
|
(cljs/join \newline)))
|
||||||
|
|
||||||
|
(defn exec-query! [qry params]
|
||||||
|
(with-open [session (db/get-session @*conn*)]
|
||||||
|
(devmode/send-to-bar
|
||||||
|
(str (butiful-query qry)
|
||||||
|
"<br>---Params---<br>"
|
||||||
|
params))
|
||||||
|
(qry session params)))
|
||||||
|
|
||||||
|
(spec/def ::tuple-query-list
|
||||||
|
(spec/coll-of
|
||||||
|
(spec/tuple fn? map?)))
|
||||||
|
(defn exec-queries! [& tuples]
|
||||||
|
{:pre [(spec/assert ::tuple-query-list tuples)]}
|
||||||
|
(db/with-transaction @*conn* tx
|
||||||
|
(doseq [tuple tuples]
|
||||||
|
(let [qry (first tuple)
|
||||||
|
params (second tuple)]
|
||||||
|
(devmode/send-to-bar
|
||||||
|
(str (butiful-query qry)
|
||||||
|
"<br>---Params---<br>"
|
||||||
|
params))
|
||||||
|
(spec/assert map? params)
|
||||||
|
(qry tx params)))))
|
||||||
|
|
||||||
|
(defn now-str []
|
||||||
|
(time-format/unparse
|
||||||
|
(time-format/formatters :basic-date-time)
|
||||||
|
(time-local/local-now)))
|
@ -0,0 +1,84 @@
|
|||||||
|
(ns wanijo.framework.repl
|
||||||
|
(:require [buddy.hashers :as hashers]
|
||||||
|
[neo4j-clj.core :as db]
|
||||||
|
[wanijo.framework.neo4j :as neo4j]))
|
||||||
|
|
||||||
|
(db/defquery create-user
|
||||||
|
"CREATE (n:user)
|
||||||
|
SET n.ident = {ident}
|
||||||
|
SET n.pw = {pw}
|
||||||
|
SET n.uuid = {uuid}")
|
||||||
|
|
||||||
|
(defn create-user! [ident pw]
|
||||||
|
(neo4j/exec-query!
|
||||||
|
create-user
|
||||||
|
{:ident ident
|
||||||
|
:pw (hashers/derive pw)
|
||||||
|
:uuid (neo4j/uuid)}))
|
||||||
|
|
||||||
|
(db/defquery init-config
|
||||||
|
"MERGE (c:dbconfig)
|
||||||
|
ON CREATE SET
|
||||||
|
c.installed_at = {now},
|
||||||
|
c.db_version = 0")
|
||||||
|
|
||||||
|
(db/defquery config
|
||||||
|
"MATCH (c:dbconfig) RETURN c")
|
||||||
|
|
||||||
|
(db/defquery ver-0-schema-uuid
|
||||||
|
"CREATE CONSTRAINT ON (n:schema)
|
||||||
|
ASSERT n.uuid IS UNIQUE")
|
||||||
|
|
||||||
|
(db/defquery ver-0-attribute-uuid
|
||||||
|
"CREATE CONSTRAINT ON (n:attribute)
|
||||||
|
ASSERT n.uuid IS UNIQUE")
|
||||||
|
|
||||||
|
(db/defquery ver-0-instance-uuid
|
||||||
|
"CREATE CONSTRAINT ON (n:instance)
|
||||||
|
ASSERT n.uuid IS UNIQUE")
|
||||||
|
|
||||||
|
(db/defquery ver-0-property-uuid
|
||||||
|
"CREATE CONSTRAINT ON (n:property)
|
||||||
|
ASSERT n.uuid IS UNIQUE")
|
||||||
|
|
||||||
|
(db/defquery ver-0-user-uuid
|
||||||
|
"CREATE CONSTRAINT ON (n:user)
|
||||||
|
ASSERT n.uuid IS UNIQUE")
|
||||||
|
|
||||||
|
(db/defquery ver-0-link-uuid
|
||||||
|
"CREATE CONSTRAINT ON (n:link)
|
||||||
|
ASSERT n.uuid IS UNIQUE")
|
||||||
|
|
||||||
|
(db/defquery ver-1-tag-name
|
||||||
|
"CREATE CONSTRAINT ON (n:tag)
|
||||||
|
ASSERT n.name IS UNIQUE")
|
||||||
|
|
||||||
|
(db/defquery ver-1-tag-uuid
|
||||||
|
"CREATE CONSTRAINT ON (n:tag)
|
||||||
|
ASSERT n.uuid IS UNIQUE")
|
||||||
|
|
||||||
|
(defn init-version-0 []
|
||||||
|
(neo4j/exec-query! ver-0-schema-uuid {})
|
||||||
|
(neo4j/exec-query! ver-0-attribute-uuid {})
|
||||||
|
(neo4j/exec-query! ver-0-instance-uuid {})
|
||||||
|
(neo4j/exec-query! ver-0-property-uuid {})
|
||||||
|
(neo4j/exec-query! ver-0-user-uuid {})
|
||||||
|
(neo4j/exec-query! ver-0-link-uuid {}))
|
||||||
|
|
||||||
|
(defn init-version-1 []
|
||||||
|
(neo4j/exec-query! ver-1-tag-name {})
|
||||||
|
(neo4j/exec-query! ver-1-tag-uuid {}))
|
||||||
|
|
||||||
|
(def migrations
|
||||||
|
[init-version-0
|
||||||
|
init-version-1])
|
||||||
|
|
||||||
|
(defn run-migrations! []
|
||||||
|
(neo4j/exec-query! init-config {:now (neo4j/now-str)})
|
||||||
|
(let [version (-> (neo4j/exec-query! config {})
|
||||||
|
first
|
||||||
|
:c
|
||||||
|
:db_version)]
|
||||||
|
(if-let [to-run (nthrest migrations version)]
|
||||||
|
(doseq [mig to-run]
|
||||||
|
(mig)))))
|
@ -1,4 +1,4 @@
|
|||||||
(ns wanijo.infra.routing
|
(ns wanijo.framework.routing
|
||||||
(:require [clojure.string :as string]))
|
(:require [clojure.string :as string]))
|
||||||
|
|
||||||
(def all-routes
|
(def all-routes
|
@ -1,4 +1,4 @@
|
|||||||
(ns wanijo.infra.time
|
(ns wanijo.framework.time
|
||||||
(:require [clj-time.format :as format]))
|
(:require [clj-time.format :as format]))
|
||||||
|
|
||||||
(defn prettify-dt [date-str]
|
(defn prettify-dt [date-str]
|
@ -0,0 +1,18 @@
|
|||||||
|
(ns wanijo.frontend.core
|
||||||
|
(:require
|
||||||
|
[reagent.core :as r]))
|
||||||
|
|
||||||
|
;; -------------------------
|
||||||
|
;; Views
|
||||||
|
|
||||||
|
(defn home-page []
|
||||||
|
[:div [:h2 "Welcome to Reagent ummf"]])
|
||||||
|
|
||||||
|
;; -------------------------
|
||||||
|
;; Initialize app
|
||||||
|
|
||||||
|
(defn mount-root []
|
||||||
|
(r/render [home-page] (.getElementById js/document "visualisation")))
|
||||||
|
|
||||||
|
(defn init! []
|
||||||
|
(mount-root))
|
@ -1,5 +1,5 @@
|
|||||||
(ns wanijo.home.view
|
(ns wanijo.home.view
|
||||||
(:require [wanijo.infra.view :as view]))
|
(:require [wanijo.framework.view :as view]))
|
||||||
|
|
||||||
(defn root! [req]
|
(defn root! [req]
|
||||||
(view/layout :request req))
|
(view/layout! :session (:session req)))
|
||||||
|
@ -1,77 +0,0 @@
|
|||||||
(ns wanijo.infra.gzip
|
|
||||||
(:require [clojure.java.io :as io])
|
|
||||||
(:import (java.io InputStream
|
|
||||||
Closeable
|
|
||||||
File
|
|
||||||
PipedInputStream
|
|
||||||
PipedOutputStream)
|
|
||||||
(java.util.zip GZIPOutputStream)))
|
|
||||||
|
|
||||||
(defn set-response-headers
|
|
||||||
[headers]
|
|
||||||
(if-let [vary (or (get headers "vary") (get headers "Vary"))]
|
|
||||||
(-> headers
|
|
||||||
(assoc "Vary" (str vary ", Accept-Encoding"))
|
|
||||||
(assoc "Content-Encoding" "gzip")
|
|
||||||
(dissoc "Content-Length" "content-length")
|
|
||||||
(dissoc "vary"))
|
|
||||||
(-> headers
|
|
||||||
(assoc "Vary" "Accept-Encoding")
|
|
||||||
(assoc "Content-Encoding" "gzip")
|
|
||||||
(dissoc "Content-Length" "content-length"))))
|
|
||||||
|
|
||||||
(defn accepts-gzip?
|
|
||||||
[req]
|
|
||||||
(if-let [accepts (get-in req [:headers "accept-encoding"])]
|
|
||||||
;; Be aggressive in supporting clients with mangled headers (due to
|
|
||||||
;; proxies, av software, buggy browsers, etc...)
|
|
||||||
(re-seq
|
|
||||||
#"(gzip\s*,?\s*(gzip|deflate)?|X{4,13}|~{4,13}|\-{4,13})"
|
|
||||||
accepts)))
|
|
||||||
|
|
||||||
(defn supported-response? [resp]
|
|
||||||
(let [{:keys [status headers body]} resp
|
|
||||||
min-bytes 859]
|
|
||||||
(and
|
|
||||||
;; correct status code
|
|
||||||
(#{200 201 202 203 204 205 403 404} status)
|
|
||||||
;; not already encoded
|
|
||||||
(not (or (headers "Content-Encoding")
|
|
||||||
(headers "content-encoding")))
|
|
||||||
;; correct data type in body
|
|
||||||
(or (string? body)
|
|
||||||
(seq? body)
|
|
||||||
(instance? InputStream body)
|
|
||||||
(and (instance? File body)
|
|
||||||
(re-seq #"(?i)\.(htm|html|css|js|json|xml)"
|
|
||||||
(pr-str body))))
|
|
||||||
;; sensible body sizes
|
|
||||||
(cond (string? body) (> (count body) min-bytes)
|
|
||||||
(seq? body) (> (count body) min-bytes)
|
|
||||||
(instance? File body) (> (.length body) min-bytes)
|
|
||||||
:else true))))
|
|
||||||
|
|
||||||
(defn compress-body [body]
|
|
||||||
(let [p-in (PipedInputStream.)
|
|
||||||
p-out (PipedOutputStream. p-in)]
|
|
||||||
(future
|
|
||||||
(with-open [out (GZIPOutputStream. p-out)]
|
|
||||||
(if (seq? body)
|
|
||||||
(doseq [string body] (io/copy (str string) out))
|
|
||||||
(io/copy body out)))
|
|
||||||
(when (instance? Closeable body)
|
|
||||||
(.close ^Closeable body)))
|
|
||||||
p-in))
|
|
||||||
|
|
||||||
(defn gzip-response [resp]
|
|
||||||
(-> resp
|
|
||||||
(update :headers set-response-headers)
|
|
||||||
(update :body compress-body)))
|
|
||||||
|
|
||||||
(defn wrap-gzip [handler]
|
|
||||||
(fn [req]
|
|
||||||
(let [resp (handler req)]
|
|
||||||
(if (and (accepts-gzip? req)
|
|
||||||
(supported-response? resp))
|
|
||||||
(gzip-response resp)
|
|
||||||
resp))))
|
|
@ -1,96 +0,0 @@
|
|||||||
(ns wanijo.infra.neo4j
|
|
||||||
(:require [neo4j-clj.core :as db]
|
|
||||||
[neo4j-clj.in-memory :as db-inm]
|
|
||||||
[clj-time.format :as time-format]
|
|
||||||
[clj-time.local :as time-local]
|
|
||||||
[clojure.spec.alpha :as spec]
|
|
||||||
[clojure.string :as cljs]
|
|
||||||
[wanijo.infra.sysconfig :refer [env]])
|
|
||||||
(:import (java.util UUID)
|
|
||||||
(java.net URI)))
|
|
||||||
|
|
||||||
(spec/def ::date-str
|
|
||||||
#(re-matches #"\d{4}\d{2}\d{2}T\d{2}\d{2}\d{2}\.\d{3}Z" %))
|
|
||||||
|
|
||||||
(spec/def ::uuid
|
|
||||||
#(re-matches
|
|
||||||
#"[0-9a-f]+-[0-9a-f]+-[0-9a-f]+-[0-9a-f]+-[0-9a-f]+" %))
|
|
||||||
|
|
||||||
(def standard-port "7687")
|
|
||||||
(def standard-host "localhost")
|
|
||||||
(def standard-user "neo4j")
|
|
||||||
(def standard-pass "b")
|
|
||||||
|
|
||||||
(defn create-conn!
|
|
||||||
([]
|
|
||||||
(let [port (env "NEO4J_PORT" standard-port)
|
|
||||||
host (env "NEO4J_HOST" standard-host)
|
|
||||||
user (env "NEO4J_USER" standard-user)
|
|
||||||
pass (env "NEO4J_PASS" standard-pass)]
|
|
||||||
(create-conn! port host user pass)))
|
|
||||||
([port host user pass]
|
|
||||||
(db/connect
|
|
||||||
(URI. (str "bolt://" host ":" port))
|
|
||||||
user
|
|
||||||
pass)))
|
|
||||||
|
|
||||||
(def conn (atom nil))
|
|
||||||
|
|
||||||
(defn reset-conn!
|
|
||||||
([]
|
|
||||||
(reset! conn (create-conn!)))
|
|
||||||
([port host user pass]
|
|
||||||
(reset! conn (create-conn! port host user pass))))
|
|
||||||
|
|
||||||
(defn in-memory-conn! []
|
|
||||||
(reset! conn (db-inm/create-in-memory-connection)))
|
|
||||||
|
|
||||||
(defonce query-strings (atom {}))
|
|
||||||
(defmacro defquery [name query]
|
|
||||||
`(do (def ~name (db/create-query ~query))
|
|
||||||
(swap! wanijo.infra.neo4j/query-strings
|
|
||||||
assoc (hash ~name) ~query)))
|
|
||||||
|
|
||||||
(defn uuid []
|
|
||||||
(str (UUID/randomUUID)))
|
|
||||||
|
|
||||||
(defn butiful-query [qry]
|
|
||||||
(->> (get @query-strings (hash qry) "unknown query")
|
|
||||||
str
|
|
||||||
cljs/trim-newline
|
|
||||||
cljs/split-lines
|
|
||||||
(map cljs/trim)
|
|
||||||
(filter #(pos? (count %)))
|
|
||||||
(cljs/join \newline)))
|
|
||||||
|
|
||||||
(def log-queries (= "true" (env "LOG_QUERIES" "false")))
|
|
||||||
(comment (def log-queries true))
|
|
||||||
|
|
||||||
(defn exec-query! [qry params]
|
|
||||||
(let [live-conn (or @conn (reset-conn!))]
|
|
||||||
(with-open [session (db/get-session live-conn)]
|
|
||||||
(when log-queries
|
|
||||||
(println (butiful-query qry) \newline params \newline))
|
|
||||||
;; neo4j-clj returns lazy lists, but when we leave with-open,
|
|
||||||
;; the ResultSet (?) is already closed, so the list cannot
|
|
||||||
;; be processed
|
|
||||||
;; doall to the rescue to force the list to be evaluated
|
|
||||||
;; eagerly
|
|
||||||
(doall (qry session params)))))
|
|
||||||
|
|
||||||
(spec/def ::tuple-query-list
|
|
||||||
(spec/coll-of
|
|
||||||
(spec/tuple fn? map?)))
|
|
||||||
(defn exec-queries! [& tuples]
|
|
||||||
{:pre [(spec/assert ::tuple-query-list tuples)]}
|
|
||||||
(db/with-transaction @conn tx
|
|
||||||
(doseq [tuple tuples]
|
|
||||||
(let [qry (first tuple)
|
|
||||||
params (second tuple)]
|
|
||||||
(spec/assert map? params)
|
|
||||||
(qry tx params)))))
|
|
||||||
|
|
||||||
(defn now-str []
|
|
||||||
(time-format/unparse
|
|
||||||
(time-format/formatters :basic-date-time)
|
|
||||||
(time-local/local-now)))
|
|
@ -1,138 +0,0 @@
|
|||||||
(ns wanijo.infra.repl
|
|
||||||
(:require [buddy.hashers :as hashers]
|
|
||||||
[wanijo.main :as main]
|
|
||||||
[wanijo.infra.neo4j :as neo4j]))
|
|
||||||
|
|
||||||
(neo4j/defquery create-user
|
|
||||||
"CREATE (n:user)
|
|
||||||
SET n.ident = $ident
|
|
||||||
SET n.pw = $pw
|
|
||||||
SET n.uuid = $uuid")
|
|
||||||
|
|
||||||
(defn create-user! [ident pw]
|
|
||||||
(neo4j/exec-query!
|
|
||||||
create-user
|
|
||||||
{:ident ident
|
|
||||||
:pw (hashers/derive pw)
|
|
||||||
:uuid (neo4j/uuid)}))
|
|
||||||
|
|
||||||
(neo4j/defquery init-config
|
|
||||||
"MERGE (c:dbconfig)
|
|
||||||
ON CREATE SET
|
|
||||||
c.installed_at = $now,
|
|
||||||
c.db_version = 0,
|
|
||||||
c.last_migration = ''")
|
|
||||||
|
|
||||||
(neo4j/defquery merge-config
|
|
||||||
"MATCH (c:dbconfig)
|
|
||||||
SET c.last_migration = $now,
|
|
||||||
c.db_version = {version}")
|
|
||||||
|
|
||||||
(neo4j/defquery config
|
|
||||||
"MATCH (c:dbconfig) RETURN c")
|
|
||||||
|
|
||||||
(neo4j/defquery ver-0-schema-uuid
|
|
||||||
"CREATE CONSTRAINT ON (n:schema)
|
|
||||||
ASSERT n.uuid IS UNIQUE")
|
|
||||||
|
|
||||||
(neo4j/defquery ver-0-attribute-uuid
|
|
||||||
"CREATE CONSTRAINT ON (n:attribute)
|
|
||||||
ASSERT n.uuid IS UNIQUE")
|
|
||||||
|
|
||||||
(neo4j/defquery ver-0-instance-uuid
|
|
||||||
"CREATE CONSTRAINT ON (n:instance)
|
|
||||||
ASSERT n.uuid IS UNIQUE")
|
|
||||||
|
|
||||||
(neo4j/defquery ver-0-property-uuid
|
|
||||||
"CREATE CONSTRAINT ON (n:property)
|
|
||||||
ASSERT n.uuid IS UNIQUE")
|
|
||||||
|
|
||||||
(neo4j/defquery ver-0-user-uuid
|
|
||||||
"CREATE CONSTRAINT ON (n:user)
|
|
||||||
ASSERT n.uuid IS UNIQUE")
|
|
||||||
|
|
||||||
(neo4j/defquery ver-0-link-uuid
|
|
||||||
"CREATE CONSTRAINT ON (n:link)
|
|
||||||
ASSERT n.uuid IS UNIQUE")
|
|
||||||
|
|
||||||
(neo4j/defquery ver-1-tag-name
|
|
||||||
"CREATE CONSTRAINT ON (n:tag)
|
|
||||||
ASSERT n.name IS UNIQUE")
|
|
||||||
|
|
||||||
(neo4j/defquery ver-1-tag-uuid
|
|
||||||
"CREATE CONSTRAINT ON (n:tag)
|
|
||||||
ASSERT n.uuid IS UNIQUE")
|
|
||||||
|
|
||||||
(defn init-version-0 []
|
|
||||||
(neo4j/exec-query! ver-0-schema-uuid {})
|
|
||||||
(neo4j/exec-query! ver-0-attribute-uuid {})
|
|
||||||
(neo4j/exec-query! ver-0-instance-uuid {})
|
|
||||||
(neo4j/exec-query! ver-0-property-uuid {})
|
|
||||||
(neo4j/exec-query! ver-0-user-uuid {})
|
|
||||||
(neo4j/exec-query! ver-0-link-uuid {}))
|
|
||||||
|
|
||||||
(defn init-version-1 []
|
|
||||||
(neo4j/exec-query! ver-1-tag-name {})
|
|
||||||
(neo4j/exec-query! ver-1-tag-uuid {}))
|
|
||||||
|
|
||||||
(neo4j/defquery migrate-links
|
|
||||||
"MATCH (i1:instance)-[lf:link_from]-(l:link)-[lt:link_to]-(i2:instance),
|
|
||||||
(l)-[cb:created_by]->(:user)
|
|
||||||
MERGE (i1)-[newl:link]->(i2)
|
|
||||||
ON CREATE SET
|
|
||||||
newl.name = l.name,
|
|
||||||
newl.created_at = l.created_at,
|
|
||||||
newl.uuid = l.uuid
|
|
||||||
DELETE cb, lf, lt, l")
|
|
||||||
|
|
||||||
(defn init-version-2 []
|
|
||||||
(neo4j/exec-query! migrate-links {}))
|
|
||||||
|
|
||||||
(neo4j/defquery migrate-permissions
|
|
||||||
"MATCH (s:schema)-[:created_by]->(u:user)
|
|
||||||
MERGE (u)-[:permission {type:'write'}]->(s)")
|
|
||||||
(defn init-version-3 []
|
|
||||||
(neo4j/exec-query! migrate-permissions {}))
|
|
||||||
|
|
||||||
(def migrations
|
|
||||||
[init-version-0
|
|
||||||
init-version-1
|
|
||||||
init-version-2
|
|
||||||
init-version-3])
|
|
||||||
|
|
||||||
(defn run-migrations! []
|
|
||||||
(neo4j/exec-query! init-config {:now (neo4j/now-str)})
|
|
||||||
(let [version (-> (neo4j/exec-query! config {})
|
|
||||||
first
|
|
||||||
:c
|
|
||||||
:db_version)]
|
|
||||||
(println "got version" version "from db," (count migrations) "available")
|
|
||||||
(when-let [to-run (nthrest migrations version)]
|
|
||||||
(println "running" (count to-run) "migrations")
|
|
||||||
(doseq [mig to-run]
|
|
||||||
(println "running" mig)
|
|
||||||
(mig))))
|
|
||||||
(neo4j/exec-query! merge-config {:now (neo4j/now-str)
|
|
||||||
:version (count migrations)})
|
|
||||||
nil)
|
|
||||||
|
|
||||||
(defn dev-server! []
|
|
||||||
(main/stop-server!)
|
|
||||||
(main/start-server-dev!)
|
|
||||||
(println "Started server at http://localhost:8080"))
|
|
||||||
|
|
||||||
(defn setup-in-memory! []
|
|
||||||
(neo4j/in-memory-conn!)
|
|
||||||
(create-user! "admin" "admin"))
|
|
||||||
|
|
||||||
(defn dev-env! []
|
|
||||||
(setup-in-memory!)
|
|
||||||
(dev-server!))
|
|
||||||
|
|
||||||
(comment
|
|
||||||
(dev-server!)
|
|
||||||
(setup-in-memory!)
|
|
||||||
(neo4j/reset-conn! "7688"
|
|
||||||
"mokoscha"
|
|
||||||
neo4j/standard-user
|
|
||||||
neo4j/standard-pass))
|
|
@ -1,7 +0,0 @@
|
|||||||
(ns wanijo.infra.sysconfig)
|
|
||||||
|
|
||||||
(defn env
|
|
||||||
([name]
|
|
||||||
(System/getenv name))
|
|
||||||
([name default]
|
|
||||||
(or (System/getenv name) default)))
|
|
@ -1,259 +0,0 @@
|
|||||||
(ns wanijo.instance.db
|
|
||||||
(:require [clojure.spec.alpha :as spec]
|
|
||||||
[wanijo.infra.neo4j :as neo4j]
|
|
||||||
[wanijo.instance.domain :as domain-instance]
|
|
||||||
[wanijo.tag.db :as db-tag]
|
|
||||||
[wanijo.instance.revision.db :as db-rev]))
|
|
||||||
|
|
||||||
(neo4j/defquery findy-by-schema
|
|
||||||
"MATCH (i:instance)-[:of]->(s:schema)
|
|
||||||
WHERE s.uuid = $uuid
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(i)-[:tagged_with]->(t:tag)
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(i)<-[:of]-(p:property),
|
|
||||||
(p)-[:of]->(a:attribute)
|
|
||||||
RETURN i, t, p, a")
|
|
||||||
(defn flatten-grouped-rows [instance grouped-rows]
|
|
||||||
{:post [(spec/assert ::domain-instance/instance-with-tags-and-props %)]}
|
|
||||||
(assoc instance
|
|
||||||
:tags (->> grouped-rows
|
|
||||||
(map :t)
|
|
||||||
(filter some?)
|
|
||||||
distinct)
|
|
||||||
:properties (->> grouped-rows
|
|
||||||
(filter #(some? (:p %)))
|
|
||||||
(map #(assoc (:p %)
|
|
||||||
:attribute (:a %)))
|
|
||||||
distinct)))
|
|
||||||
(defn find-by-schema! [schema-uuid]
|
|
||||||
{:post [(spec/assert ::domain-instance/instances-with-tags-and-props %)]}
|
|
||||||
(->> (neo4j/exec-query! findy-by-schema
|
|
||||||
{:uuid schema-uuid})
|
|
||||||
(group-by :i)
|
|
||||||
(map #(flatten-grouped-rows (key %) (val %)))
|
|
||||||
(sort-by :name)))
|
|
||||||
|
|
||||||
(neo4j/defquery create-instance
|
|
||||||
"MATCH (s:schema {uuid: $schema_uuid}),
|
|
||||||
(u:user {uuid: $user_uuid})
|
|
||||||
CREATE (i:instance {uuid: $uuid})-[:of]->(s),
|
|
||||||
(i)-[:created_by]->(u)
|
|
||||||
SET i.name = $name,
|
|
||||||
i.created_at = $created_at,
|
|
||||||
i.updated_at = $created_at")
|
|
||||||
(neo4j/defquery create-property
|
|
||||||
"MATCH (i:instance {uuid: $uuid}),
|
|
||||||
(a:attribute {uuid: $attr_uuid})
|
|
||||||
CREATE (p:property {uuid: $prop_uuid})-[:of]->(i),
|
|
||||||
(p)-[:of]->(a)
|
|
||||||
SET p.value = $value,
|
|
||||||
p.created_at = $created_at,
|
|
||||||
p.updated_at = $updated_at")
|
|
||||||
(defn create! [user-uuid
|
|
||||||
schema-uuid
|
|
||||||
{:keys [name properties]}]
|
|
||||||
(let [instance-uuid (neo4j/uuid)
|
|
||||||
now (neo4j/now-str)
|
|
||||||
instance-tuple [create-instance
|
|
||||||
{:schema_uuid schema-uuid
|
|
||||||
:name name
|
|
||||||
:uuid instance-uuid
|
|
||||||
:created_at now
|
|
||||||
:user_uuid user-uuid}]
|
|
||||||
prop-tuples (for [{:keys [attribute value]} properties]
|
|
||||||
[create-property
|
|
||||||
{:uuid instance-uuid
|
|
||||||
:attr_uuid (:uuid attribute)
|
|
||||||
:prop_uuid (neo4j/uuid)
|
|
||||||
:value value
|
|
||||||
:created_at now
|
|
||||||
:updated_at now}])]
|
|
||||||
(apply neo4j/exec-queries!
|
|
||||||
(concat [instance-tuple]
|
|
||||||
prop-tuples))))
|
|
||||||
|
|
||||||
(neo4j/defquery find-by-uuid
|
|
||||||
"MATCH (i:instance {uuid: $uuid})-[:of]->(s:schema)
|
|
||||||
RETURN i, s")
|
|
||||||
(defn find-by-uuid! [uuid]
|
|
||||||
{:post [(spec/assert ::domain-instance/instance-with-schema %)]}
|
|
||||||
(->> (neo4j/exec-query! find-by-uuid
|
|
||||||
{:uuid uuid})
|
|
||||||
(map #(assoc (:i %)
|
|
||||||
:schema
|
|
||||||
(:s %)))
|
|
||||||
first))
|
|
||||||
|
|
||||||
(neo4j/defquery find-properties
|
|
||||||
"MATCH (i:instance {uuid: $uuid}),
|
|
||||||
(p:property)-[:of]->(i),
|
|
||||||
(p)-[:of]->(a:attribute)
|
|
||||||
RETURN p, a
|
|
||||||
ORDER BY a.name")
|
|
||||||
(defn find-properties! [uuid]
|
|
||||||
(map #(assoc (:p %)
|
|
||||||
:attribute
|
|
||||||
(:a %))
|
|
||||||
(neo4j/exec-query! find-properties
|
|
||||||
{:uuid uuid})))
|
|
||||||
|
|
||||||
(neo4j/defquery edit-instance
|
|
||||||
"MATCH (i:instance {uuid: $uuid})
|
|
||||||
SET i.name = $name,
|
|
||||||
i.updated_at = $updated_at")
|
|
||||||
(neo4j/defquery edit-property
|
|
||||||
"MATCH (i:instance {uuid: $instance_uuid}),
|
|
||||||
(a:attribute {uuid: $attribute_uuid})
|
|
||||||
MERGE (p:property {uuid: $uuid})-[:of]->(i)
|
|
||||||
MERGE (p)-[:of]->(a)
|
|
||||||
ON CREATE SET p.created_at = $now,
|
|
||||||
p.updated_at = $now,
|
|
||||||
p.value = $value
|
|
||||||
ON MATCH SET p.updated_at = $now,
|
|
||||||
p.value = $value")
|
|
||||||
(defn instance->prop-tuples [instance]
|
|
||||||
{:post [(spec/assert ::domain-instance/prop-tuple %)]}
|
|
||||||
(map (fn [prop]
|
|
||||||
(let [prop-uuid (:uuid prop)
|
|
||||||
uuid (if (empty? prop-uuid)
|
|
||||||
(neo4j/uuid)
|
|
||||||
prop-uuid)]
|
|
||||||
[edit-property
|
|
||||||
{:uuid uuid
|
|
||||||
:now (neo4j/now-str)
|
|
||||||
:value (:value prop)
|
|
||||||
:instance_uuid (:uuid instance)
|
|
||||||
:attribute_uuid (-> prop :attribute :uuid)}]))
|
|
||||||
(:properties instance)))
|
|
||||||
(defn edit! [instance revision]
|
|
||||||
(let [prop-tuples (instance->prop-tuples instance)]
|
|
||||||
(apply neo4j/exec-queries!
|
|
||||||
(concat [[edit-instance
|
|
||||||
{:uuid (:uuid instance)
|
|
||||||
:name (:name instance)
|
|
||||||
:updated_at (neo4j/now-str)}]]
|
|
||||||
prop-tuples
|
|
||||||
(db-rev/revision-queries revision)))))
|
|
||||||
|
|
||||||
(comment
|
|
||||||
(db-rev/revision-queries
|
|
||||||
{:instance-name "dings"
|
|
||||||
:instance-uuid "4711"
|
|
||||||
:properties [{:type "string"
|
|
||||||
:value "dings-prop"}]}))
|
|
||||||
|
|
||||||
(neo4j/defquery delete
|
|
||||||
"MATCH (i:instance {uuid: $uuid}),
|
|
||||||
(i)-[ic:of]->(s:schema),
|
|
||||||
(i)-[cb:created_by]->(:user)
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(p:property)-[pc:of]->(i),
|
|
||||||
(p)-[pac:of]->(a:attribute)
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(i)-[tw:tagged_with]->()
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(i)-[l:link]-()
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(i)<-[ric:of]-(rev:revision)
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(rev_prop:rev_property)-[rpc:of]->(rev)
|
|
||||||
DELETE pac, pc, cb, ic, p,
|
|
||||||
l, tw, i, ric,
|
|
||||||
rpc, rev_prop, rev")
|
|
||||||
(defn delete! [uuid]
|
|
||||||
(neo4j/exec-query! delete {:uuid uuid}))
|
|
||||||
|
|
||||||
(defn group-by-link-and-assoc-tags [uuid query direction]
|
|
||||||
(->> (neo4j/exec-query! query {:uuid uuid})
|
|
||||||
(group-by #(hash-map :link (:link %)
|
|
||||||
:schema (:schema %)
|
|
||||||
direction (direction %)))
|
|
||||||
(map (fn [[link tags]]
|
|
||||||
(let [tags (map :tag tags)]
|
|
||||||
(assoc link
|
|
||||||
:tags (filter some? tags)))))
|
|
||||||
(sort-by (juxt #(-> % :schema :name)
|
|
||||||
#(-> % direction :name)
|
|
||||||
#(-> % direction :created_at)))))
|
|
||||||
|
|
||||||
(neo4j/defquery outgoing-links
|
|
||||||
"MATCH (inst:instance {uuid: $uuid}),
|
|
||||||
(inst)-[link:link]->(target:instance),
|
|
||||||
(target)-[:of]->(schema:schema)
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(target)-[:tagged_with]->(tag:tag)
|
|
||||||
RETURN link, target, schema, tag")
|
|
||||||
(defn outgoing-links! [uuid]
|
|
||||||
{:post [(spec/assert ::domain-instance/links-out %)]}
|
|
||||||
(group-by-link-and-assoc-tags uuid outgoing-links :target))
|
|
||||||
|
|
||||||
(neo4j/defquery incoming-links
|
|
||||||
"MATCH (inst:instance {uuid: $uuid}),
|
|
||||||
(inst)<-[link:link]-(source:instance),
|
|
||||||
(source)-[:of]->(schema:schema)
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(source)-[:tagged_with]->(tag:tag)
|
|
||||||
RETURN link, source, schema, tag
|
|
||||||
ORDER BY schema.name, source.name, source.created_at")
|
|
||||||
(defn incoming-links! [uuid]
|
|
||||||
{:post [(spec/assert ::domain-instance/links-in %)]}
|
|
||||||
(group-by-link-and-assoc-tags uuid incoming-links :source))
|
|
||||||
|
|
||||||
(defn full-instance-by-uuid! [uuid]
|
|
||||||
{:post [(spec/assert ::domain-instance/full-instance %)]}
|
|
||||||
(assoc (find-by-uuid! uuid)
|
|
||||||
:properties
|
|
||||||
(find-properties! uuid)
|
|
||||||
:links-out
|
|
||||||
(outgoing-links! uuid)
|
|
||||||
:links-in
|
|
||||||
(incoming-links! uuid)
|
|
||||||
:tags
|
|
||||||
(db-tag/tags-by-instance! uuid)))
|
|
||||||
|
|
||||||
(neo4j/defquery is-starred
|
|
||||||
"MATCH (u:user {uuid: $user_uuid}),
|
|
||||||
(i:instance {uuid: $uuid})
|
|
||||||
RETURN EXISTS((i)-[:starred_by]->(u)) AS starred")
|
|
||||||
(defn is-starred! [uuid user-uuid]
|
|
||||||
(-> (neo4j/exec-query! is-starred
|
|
||||||
{:user_uuid user-uuid
|
|
||||||
:uuid uuid})
|
|
||||||
first
|
|
||||||
:starred))
|
|
||||||
|
|
||||||
(neo4j/defquery mark-starred
|
|
||||||
"MATCH (i:instance {uuid: $uuid}),
|
|
||||||
(u:user {uuid: $user_uuid})
|
|
||||||
MERGE (i)-[s:starred_by]->(u)
|
|
||||||
ON CREATE
|
|
||||||
SET s.created_at = $now")
|
|
||||||
(defn mark-starred! [uuid user-uuid]
|
|
||||||
(neo4j/exec-query! mark-starred
|
|
||||||
{:uuid uuid
|
|
||||||
:user_uuid user-uuid
|
|
||||||
:now (neo4j/now-str)}))
|
|
||||||
|
|
||||||
(neo4j/defquery remove-starred
|
|
||||||
"MATCH (:instance {uuid: $uuid})
|
|
||||||
-[s:starred_by]->
|
|
||||||
(:user {uuid: $user_uuid})
|
|
||||||
DELETE s")
|
|
||||||
(defn remove-starred! [uuid user-uuid]
|
|
||||||
(neo4j/exec-query! remove-starred
|
|
||||||
{:uuid uuid
|
|
||||||
:user_uuid user-uuid}))
|
|
||||||
|
|
||||||
(neo4j/defquery starred-by-user
|
|
||||||
"MATCH (u:user {uuid: $user_uuid})
|
|
||||||
<-[s:starred_by]-
|
|
||||||
(i:instance)
|
|
||||||
RETURN i, s
|
|
||||||
ORDER BY s.created_at DESC")
|
|
||||||
(defn starred-by-user! [user-uuid]
|
|
||||||
(map #(assoc (:i %)
|
|
||||||
:starred_at (-> % :s :created_at))
|
|
||||||
(neo4j/exec-query! starred-by-user
|
|
||||||
{:user_uuid user-uuid})))
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
|||||||
(ns wanijo.instance.files
|
|
||||||
(:require [clojure.java.io :as io]
|
|
||||||
[wanijo.infra.sysconfig :refer [env]]
|
|
||||||
[wanijo.infra.neo4j :refer [uuid]])
|
|
||||||
(:import [java.io File]))
|
|
||||||
|
|
||||||
(def files-home (str (env "WANIJO_HOME") "/files"))
|
|
||||||
|
|
||||||
(comment
|
|
||||||
(def files-home "/tmp/wanijo"))
|
|
||||||
|
|
||||||
(defn persist-files! [instance]
|
|
||||||
(doall
|
|
||||||
(for [file (->> (:properties instance)
|
|
||||||
(filter #(= "file" (-> % :attribute :type)))
|
|
||||||
(map (fn [prop] {:file (:value prop)
|
|
||||||
:uuid (:uuid prop)})))
|
|
||||||
:let [uploaded-file (:file file)
|
|
||||||
size (:size uploaded-file)
|
|
||||||
uuid (if (empty? (:uuid file)) (uuid) (:uuid file))
|
|
||||||
path (str files-home "/" uuid)]
|
|
||||||
:when (> size 0)]
|
|
||||||
(do
|
|
||||||
(.mkdirs (io/file files-home))
|
|
||||||
(io/copy (io/file (:tempfile uploaded-file)) (io/file path))
|
|
||||||
{:path path
|
|
||||||
:uuid uuid
|
|
||||||
:filename (:filename uploaded-file)
|
|
||||||
:content-type (:content-type uploaded-file)}))))
|
|
||||||
|
|
||||||
(comment
|
|
||||||
(let [instance {:name "Frank",
|
|
||||||
:properties
|
|
||||||
'({:attribute
|
|
||||||
{:name "Dateidings",
|
|
||||||
:created_at "20210929T154103.152Z",
|
|
||||||
:type "file",
|
|
||||||
:uuid "00847b4c-9961-47cd-a64f-18eaea0e362f",
|
|
||||||
:required 0},
|
|
||||||
:value
|
|
||||||
{:filename "2020.pdf",
|
|
||||||
:content-type "application/pdf",
|
|
||||||
:tempfile nil,
|
|
||||||
:size 127785},
|
|
||||||
:uuid "f7d56f9c-e74a-4b12-95c1-f33961672072"}),
|
|
||||||
:uuid "def4dacb-979f-4a0d-b1d6-535ac2a3f94b"}]
|
|
||||||
(->> (:properties instance)
|
|
||||||
(filter #(= "file" 1 #_(-> % :attribute :type))) #_(map (fn [prop] {:file (:value prop)
|
|
||||||
:uuid (:uuid prop)}))))
|
|
||||||
)
|
|
@ -1,33 +0,0 @@
|
|||||||
(ns wanijo.instance.revision.db
|
|
||||||
(:require [wanijo.infra.neo4j :as neo4j]))
|
|
||||||
|
|
||||||
(neo4j/defquery save-revision
|
|
||||||
"MATCH (i:instance)
|
|
||||||
WHERE i.uuid = $uuid
|
|
||||||
CREATE (r:revision)-[:of]->(i)
|
|
||||||
SET r.uuid = $rev_uuid,
|
|
||||||
r.instance_name = $name,
|
|
||||||
r.created_at = $now")
|
|
||||||
(neo4j/defquery save-revision-property
|
|
||||||
"MATCH (r:revision)
|
|
||||||
WHERE r.uuid = $rev_uuid
|
|
||||||
CREATE (rp:rev_property)-[:of]->(r)
|
|
||||||
SET rp.uuid = $rp_uuid,
|
|
||||||
rp.value = $value,
|
|
||||||
rp.type = $type,
|
|
||||||
rp.created_at = $now")
|
|
||||||
(defn revision-queries [revision]
|
|
||||||
(let [rev-uuid (neo4j/uuid)]
|
|
||||||
(concat [[save-revision
|
|
||||||
{:uuid (:instance-uuid revision)
|
|
||||||
:rev_uuid rev-uuid
|
|
||||||
:name (:instance-name revision)
|
|
||||||
:now (neo4j/now-str)}]]
|
|
||||||
(map (fn [{:keys [value type]}]
|
|
||||||
[save-revision-property
|
|
||||||
{:rev_uuid rev-uuid
|
|
||||||
:rp_uuid (neo4j/uuid)
|
|
||||||
:value value
|
|
||||||
:type type
|
|
||||||
:now (neo4j/now-str)}])
|
|
||||||
(:properties revision)))))
|
|
@ -1,251 +1,166 @@
|
|||||||
(ns wanijo.instance.routes
|
(ns wanijo.instance.routes
|
||||||
(:require [compojure.core :refer [defroutes wrap-routes
|
(:require [compojure.core :refer [defroutes wrap-routes
|
||||||
GET POST DELETE]
|
GET POST DELETE]]
|
||||||
:as compojure]
|
|
||||||
[ring.util.response :as resp]
|
[ring.util.response :as resp]
|
||||||
[formulare.core :as form]
|
[formulare.core :as form]
|
||||||
[wanijo.instance.view
|
|
||||||
[edit :refer [edit]]
|
|
||||||
[instances :refer [instances]]
|
|
||||||
[show :refer [show]]
|
|
||||||
[link-selection :refer [link-selection]]
|
|
||||||
[bulk-link-selection :refer [bulk-link-selection]]
|
|
||||||
[starred :refer [starred]]]
|
|
||||||
[wanijo.instance
|
[wanijo.instance
|
||||||
[db :as db]
|
[view :as view]
|
||||||
[forms :as forms-inst]
|
|
||||||
[domain :as domain]
|
[domain :as domain]
|
||||||
[files :as files]]
|
[forms :as forms-inst]]
|
||||||
[wanijo.schema.db :as domain-schema]
|
[wanijo.schema
|
||||||
[wanijo.schema.middleware :as middleware-schema]
|
[domain :as domain-schema]
|
||||||
[wanijo.link.db :as domain-link]
|
[middleware :as middleware-schema]]
|
||||||
[wanijo.infra.routing :refer [register! path]]
|
[wanijo.framework.routing :refer [register! path]]
|
||||||
[wanijo.attribute.db :as db-attr]))
|
[wanijo.attribute.domain :as domain-attr]))
|
||||||
|
|
||||||
(defn route-list! [schema-uuid req]
|
(defn list! [schema-uuid req]
|
||||||
(instances (domain-schema/find-by-uuid! schema-uuid)
|
(view/list! (domain-schema/find-by-uuid! schema-uuid)
|
||||||
(db/find-by-schema! schema-uuid)
|
(domain/find-by-schema! schema-uuid)
|
||||||
(forms-inst/with-attributes (db-attr/required! schema-uuid))
|
(forms-inst/with-attributes (domain-attr/required! schema-uuid))
|
||||||
req))
|
req))
|
||||||
|
|
||||||
(defn route-new! [req]
|
(defn new! [req]
|
||||||
(let [schema-uuid (get-in req [:params :schema-uuid])
|
(let [schema-uuid (get-in req [:params :schema-uuid])
|
||||||
user-uuid (get-in req [:session :uuid])
|
user-uuid (get-in req [:session :uuid])
|
||||||
req-attrs (db-attr/required! schema-uuid)
|
req-attrs (domain-attr/required! schema-uuid)
|
||||||
form-def (forms-inst/with-attributes req-attrs)]
|
form-def (forms-inst/with-attributes req-attrs)]
|
||||||
(if (form/valid? form-def req)
|
(if (form/valid? form-def req)
|
||||||
(let [form-data (form/form-data form-def req)
|
(let [form-data (form/form-data form-def req)
|
||||||
req-attrs (db-attr/required! schema-uuid)
|
req-attrs (domain-attr/required! schema-uuid)
|
||||||
instance (forms-inst/form-data->instance form-data
|
instance (forms-inst/form-data->instance form-data
|
||||||
req-attrs)]
|
req-attrs)]
|
||||||
(db/create! user-uuid
|
(domain/create! user-uuid
|
||||||
schema-uuid
|
schema-uuid
|
||||||
instance)
|
instance)
|
||||||
(resp/redirect (path :instance-list
|
(resp/redirect (path :instance-list
|
||||||
(:params req))))
|
(:params req))))
|
||||||
(route-list! schema-uuid req))))
|
(list! schema-uuid req))))
|
||||||
|
|
||||||
(defn instance! [uuid]
|
(defn instance! [uuid]
|
||||||
(db/full-instance-by-uuid! uuid))
|
(domain/full-instance-by-uuid! uuid))
|
||||||
|
|
||||||
(defn route-show! [uuid req]
|
(defn show! [uuid req]
|
||||||
(let [user-uuid (-> req :session :uuid)
|
(let [user-uuid (-> req :session :uuid)
|
||||||
instance (assoc (instance! uuid)
|
instance (assoc (instance! uuid)
|
||||||
:starred
|
:starred
|
||||||
(db/is-starred! uuid
|
(domain/is-starred! uuid
|
||||||
user-uuid))]
|
user-uuid))]
|
||||||
(show instance
|
(view/show! instance
|
||||||
(domain-schema/accessible-schemas! user-uuid)
|
(domain-schema/accessible-schemas! user-uuid)
|
||||||
req)))
|
req)))
|
||||||
|
|
||||||
(defn route-edit-form! [uuid req]
|
(defn form! [uuid attrs]
|
||||||
|
(forms-inst/with-attributes attrs))
|
||||||
|
|
||||||
|
(defn edit-form! [uuid req]
|
||||||
(let [instance (instance! uuid)
|
(let [instance (instance! uuid)
|
||||||
attrs (db-attr/find-by-instance! uuid)
|
attrs (domain-attr/find-by-instance! uuid)
|
||||||
user-uuid (get-in req [:session :uuid])]
|
user-uuid (get-in req [:session :uuid])]
|
||||||
(edit instance
|
(view/edit! instance
|
||||||
(forms-inst/with-attributes attrs)
|
(form! uuid attrs)
|
||||||
(forms-inst/instance->form-data instance)
|
(forms-inst/instance->form-data instance)
|
||||||
(domain-schema/accessible-schemas! user-uuid)
|
(domain-schema/accessible-schemas! user-uuid)
|
||||||
req)))
|
req)))
|
||||||
|
|
||||||
(comment
|
(defn edit! [uuid req]
|
||||||
(forms-inst/with-attributes
|
(let [attrs (domain-attr/find-by-instance! uuid)
|
||||||
(db-attr/find-by-instance!
|
form-def (form! uuid attrs)
|
||||||
"def4dacb-979f-4a0d-b1d6-535ac2a3f94b")))
|
instance (instance! uuid)]
|
||||||
|
|
||||||
(defn route-edit! [uuid req]
|
|
||||||
(let [attrs (db-attr/find-by-instance! uuid)
|
|
||||||
form-def (forms-inst/with-attributes attrs)]
|
|
||||||
(if (form/valid? form-def req)
|
(if (form/valid? form-def req)
|
||||||
(let [form-data (form/form-data form-def req)
|
(let [form-data (form/form-data form-def req)
|
||||||
form-instance (forms-inst/form-data->instance form-data attrs)
|
form-instance (forms-inst/form-data->instance form-data attrs)
|
||||||
instance (assoc form-instance :uuid uuid)]
|
instance (assoc form-instance :uuid uuid)]
|
||||||
(db/edit! instance (domain/to-revision instance))
|
(domain/edit! instance)
|
||||||
(resp/redirect (path :instance-show instance)))
|
(resp/redirect (path :instance-show instance)))
|
||||||
(route-show! uuid req))))
|
(show! uuid req))))
|
||||||
|
|
||||||
(defn route-delete! [uuid]
|
(defn delete! [uuid req]
|
||||||
(let [schema (domain-schema/find-by-instance! uuid)]
|
(let [schema (domain-schema/find-by-instance! uuid)]
|
||||||
(db/delete! uuid)
|
(domain/delete! uuid)
|
||||||
(resp/redirect (path :instance-list
|
(resp/redirect (path :instance-list
|
||||||
{:schema-uuid (:uuid schema)}))))
|
{:schema-uuid (:uuid schema)}))))
|
||||||
|
|
||||||
(defn link-form! [schema-uuid]
|
(defn link-form! [schema-uuid]
|
||||||
(forms-inst/link-form
|
(forms-inst/link-form
|
||||||
(db/find-by-schema! schema-uuid)))
|
(domain/find-by-schema! schema-uuid)))
|
||||||
|
|
||||||
(defn route-link-selection! [uuid schema-uuid req]
|
(defn link-selection! [uuid schema-uuid req]
|
||||||
(link-selection (instance! uuid)
|
(view/link-selection (instance! uuid)
|
||||||
(domain-schema/find-by-uuid! schema-uuid)
|
(domain-schema/find-by-uuid! schema-uuid)
|
||||||
(link-form! schema-uuid)
|
(link-form! schema-uuid)
|
||||||
req))
|
req))
|
||||||
|
|
||||||
(defn route-create-link! [uuid schema-uuid req]
|
(defn create-link! [uuid schema-uuid req]
|
||||||
(let [form (link-form! schema-uuid)]
|
(let [form (link-form! schema-uuid)]
|
||||||
(if (form/valid? form req)
|
(if (form/valid? form req)
|
||||||
(let [form-data (form/form-data form req)]
|
(let [form-data (form/form-data form req)]
|
||||||
(domain-link/create! {:from uuid
|
(domain/create-link! {:from uuid
|
||||||
:name (:name form-data)
|
:name (:name form-data)
|
||||||
:to (:instances form-data)
|
:to (:instances form-data)
|
||||||
:by (get-in req [:session :uuid])})
|
:by (get-in req [:session :uuid])})
|
||||||
(resp/redirect (path :instance-edit-form {:uuid uuid})))
|
(resp/redirect (path :instance-edit-form {:uuid uuid})))
|
||||||
(route-link-selection! uuid schema-uuid req))))
|
(link-selection! uuid schema-uuid req))))
|
||||||
|
|
||||||
(comment
|
|
||||||
(form/valid? (link-form! "6e7009e3-724b-4fce-afe0-7cf50f0bfcff")
|
|
||||||
{:params {:name "link-name"
|
|
||||||
:instances ["4bb90cc3-54d1-4d7d-bc30-c357777613ef"]}}))
|
|
||||||
|
|
||||||
(defn route-delete-link! [uuid link-uuid]
|
(defn delete-link! [uuid link-uuid req]
|
||||||
(domain-link/delete! link-uuid)
|
(domain/delete-link! link-uuid)
|
||||||
(resp/redirect (path :instance-edit-form {:uuid uuid})))
|
(resp/redirect (path :instance-edit-form {:uuid uuid})))
|
||||||
|
|
||||||
(defn route-mark-starred! [uuid req]
|
(defn mark-starred! [uuid req]
|
||||||
(db/mark-starred! uuid
|
(domain/mark-starred! uuid
|
||||||
(-> req :session :uuid))
|
(-> req :session :uuid))
|
||||||
(resp/redirect (path :instance-show {:uuid uuid})))
|
(resp/redirect (path :instance-show {:uuid uuid})))
|
||||||
|
|
||||||
(defn route-remove-starred! [uuid req]
|
(defn remove-starred! [uuid req]
|
||||||
(db/remove-starred! uuid
|
(domain/remove-starred! uuid
|
||||||
(-> req :session :uuid))
|
(-> req :session :uuid))
|
||||||
(resp/redirect (path :instance-show {:uuid uuid})))
|
(resp/redirect (path :instance-show {:uuid uuid})))
|
||||||
|
|
||||||
(defn route-list-starred! [req]
|
(defn list-starred! [req]
|
||||||
(starred
|
(view/list-starred
|
||||||
(db/starred-by-user! (-> req :session :uuid))
|
(domain/starred-by-user! (-> req :session :uuid))
|
||||||
req))
|
req))
|
||||||
|
|
||||||
(defn route-bulk-link-selection! [uuid req]
|
|
||||||
(let [user-uuid (-> req :session :uuid)]
|
|
||||||
(bulk-link-selection (db/full-instance-by-uuid! uuid)
|
|
||||||
(->> (domain-schema/accessible-schemas!
|
|
||||||
user-uuid)
|
|
||||||
(map (fn [schema]
|
|
||||||
{:schema schema
|
|
||||||
:instances (db/find-by-schema!
|
|
||||||
(:uuid schema))})))
|
|
||||||
req)))
|
|
||||||
|
|
||||||
(defn route-create-bulk-link! [uuid req]
|
|
||||||
(let [names (-> req :params :name)
|
|
||||||
instances (-> req :params :instances)
|
|
||||||
source-uuid (-> req :params :source-uuid)]
|
|
||||||
; (clojure.pprint/pprint names)
|
|
||||||
; (clojure.pprint/pprint instances)
|
|
||||||
; (clojure.pprint/pprint source-uuid)
|
|
||||||
#_(clojure.pprint/pprint
|
|
||||||
(map (fn [[target-schema target-instances]]
|
|
||||||
{:link-name (get names target-schema)
|
|
||||||
:instances target-instances})
|
|
||||||
instances)))
|
|
||||||
(resp/redirect (path :instance-show {:uuid uuid})))
|
|
||||||
|
|
||||||
(defn schema-uuid-by-instance [req]
|
|
||||||
(-> (get-in req [:params :uuid])
|
|
||||||
(domain-schema/find-by-instance!)
|
|
||||||
:uuid))
|
|
||||||
|
|
||||||
(defn schema-uuid-from-params [req]
|
|
||||||
(get-in req [:params :schema-uuid]))
|
|
||||||
|
|
||||||
(def linking-routes
|
|
||||||
(-> (compojure/routes
|
|
||||||
(GET (register! :instance-link-selection
|
|
||||||
"/instance/:uuid/link/:schema-uuid")
|
|
||||||
[uuid schema-uuid :as req]
|
|
||||||
(route-link-selection! uuid schema-uuid req))
|
|
||||||
(POST (register! :instance-link-create
|
|
||||||
"/instance/:uuid/link/:schema-uuid")
|
|
||||||
[uuid schema-uuid :as req]
|
|
||||||
(route-create-link! uuid schema-uuid req)))
|
|
||||||
(wrap-routes
|
|
||||||
(middleware-schema/wrap-allowed-to-write!
|
|
||||||
#(get-in % [:params :schema-uuid])))
|
|
||||||
(wrap-routes
|
|
||||||
(middleware-schema/wrap-allowed-to-write!
|
|
||||||
schema-uuid-by-instance))))
|
|
||||||
|
|
||||||
(def writing-routes-with-uuid-in-path
|
|
||||||
(wrap-routes
|
|
||||||
(compojure/routes
|
|
||||||
(GET (register! :instance-edit-form "/instance/:uuid/edit")
|
|
||||||
[uuid :as req]
|
|
||||||
(route-edit-form! uuid req))
|
|
||||||
(POST (register! :instance-edit "/instance/:uuid")
|
|
||||||
[uuid :as req]
|
|
||||||
(route-edit! uuid req))
|
|
||||||
(DELETE (register! :instance-delete "/instance/:uuid")
|
|
||||||
[uuid]
|
|
||||||
(route-delete! uuid))
|
|
||||||
(DELETE (register! :instance-link-delete
|
|
||||||
"/instance/:uuid/link/:link-uuid")
|
|
||||||
[uuid link-uuid]
|
|
||||||
(route-delete-link! uuid link-uuid))
|
|
||||||
(POST (register! :instance-mark-starred
|
|
||||||
"/instance/:uuid/starred")
|
|
||||||
[uuid :as req]
|
|
||||||
(route-mark-starred! uuid req))
|
|
||||||
(DELETE (register! :instance-remove-starred
|
|
||||||
"/instance/:uuid/starred")
|
|
||||||
[uuid :as req]
|
|
||||||
(route-remove-starred! uuid req))
|
|
||||||
(GET (register! :instance-bulk-link-selection "/instance/:uuid/bulk-link")
|
|
||||||
[uuid :as req]
|
|
||||||
(route-bulk-link-selection! uuid req))
|
|
||||||
(POST (register! :instance-bulk-link-create "/instance/:uuid/bulk-link")
|
|
||||||
[uuid :as req]
|
|
||||||
(route-create-bulk-link! uuid req)))
|
|
||||||
(middleware-schema/wrap-allowed-to-write!
|
|
||||||
schema-uuid-by-instance)))
|
|
||||||
|
|
||||||
(defroutes routes
|
(defroutes routes
|
||||||
;; read routes with :schema-uuid
|
|
||||||
(wrap-routes
|
|
||||||
(compojure/routes
|
|
||||||
(GET (register! :instance-list "/instance/list/:schema-uuid")
|
|
||||||
[schema-uuid :as req]
|
|
||||||
(route-list! schema-uuid req)))
|
|
||||||
(middleware-schema/wrap-allowed-to-read!
|
|
||||||
schema-uuid-from-params))
|
|
||||||
(wrap-routes
|
(wrap-routes
|
||||||
(compojure/routes
|
(GET (register! :instance-list "/instance/list/:schema-uuid")
|
||||||
(GET (register! :instance-show "/instance/:uuid")
|
[schema-uuid :as req]
|
||||||
[uuid :as req]
|
(list! schema-uuid req))
|
||||||
(route-show! uuid req)))
|
(middleware-schema/wrap-allowed-to-read
|
||||||
(middleware-schema/wrap-allowed-to-read!
|
#(get-in % [:params :schema-uuid])))
|
||||||
schema-uuid-by-instance))
|
(POST (register! :instance-new "/instance/new") []
|
||||||
(wrap-routes
|
new!)
|
||||||
(compojure/routes
|
(GET (register! :instance-show "/instance/:uuid")
|
||||||
(POST (register! :instance-new "/instance/new") []
|
[uuid :as req]
|
||||||
route-new!))
|
(show! uuid req))
|
||||||
(middleware-schema/wrap-allowed-to-write!
|
(GET (register! :instance-edit-form "/instance/:uuid/edit")
|
||||||
schema-uuid-from-params))
|
[uuid :as req]
|
||||||
linking-routes
|
(edit-form! uuid req))
|
||||||
writing-routes-with-uuid-in-path
|
(POST (register! :instance-edit "/instance/:uuid")
|
||||||
|
[uuid :as req]
|
||||||
|
(edit! uuid req))
|
||||||
|
(DELETE (register! :instance-delete "/instance/:uuid")
|
||||||
|
[uuid :as req]
|
||||||
|
(delete! uuid req))
|
||||||
|
(GET (register! :instance-link-selection
|
||||||
|
"/instance/:uuid/link/:schema-uuid")
|
||||||
|
[uuid schema-uuid :as req]
|
||||||
|
(link-selection! uuid schema-uuid req))
|
||||||
|
(POST (register! :instance-link-create
|
||||||
|
"/instance/:uuid/link/:schema-uuid")
|
||||||
|
[uuid schema-uuid :as req]
|
||||||
|
(create-link! uuid schema-uuid req))
|
||||||
|
(DELETE (register! :instance-link-delete
|
||||||
|
"/instance/:uuid/link/:link-uuid")
|
||||||
|
[uuid link-uuid :as req]
|
||||||
|
(delete-link! uuid link-uuid req))
|
||||||
|
(POST (register! :instance-mark-starred
|
||||||
|
"/instance/:uuid/starred")
|
||||||
|
[uuid :as req]
|
||||||
|
(mark-starred! uuid req))
|
||||||
|
(DELETE (register! :instance-remove-starred
|
||||||
|
"/instance/:uuid/starred")
|
||||||
|
[uuid :as req]
|
||||||
|
(remove-starred! uuid req))
|
||||||
(GET (register! :instance-list-starred "/instance/starred/list")
|
(GET (register! :instance-list-starred "/instance/starred/list")
|
||||||
[:as req]
|
[:as req]
|
||||||
;; at some point someone will star an instance and then permissions to
|
(list-starred! req)))
|
||||||
;; the schema will be revoked
|
|
||||||
;; the instances will still be visible but can't be opened anymore
|
|
||||||
;; because of missing permissions, so they can't be unstared anymore
|
|
||||||
(route-list-starred! req)))
|
|
||||||
|
@ -0,0 +1,255 @@
|
|||||||
|
(ns wanijo.instance.view
|
||||||
|
(:require [hiccup
|
||||||
|
[form :as hform]
|
||||||
|
[core :refer [h]]]
|
||||||
|
[ring.util.anti-forgery :refer [anti-forgery-field]]
|
||||||
|
[markdown.core :as md]
|
||||||
|
[formulare.core :as form]
|
||||||
|
[wanijo.tag.view :as view-tag]
|
||||||
|
[wanijo.instance.domain :as domain]
|
||||||
|
[wanijo.visualisation.viz :as viz]
|
||||||
|
[wanijo.framework
|
||||||
|
[view :as view]
|
||||||
|
[routing :refer [path]]
|
||||||
|
[time :refer [prettify-dt]]]))
|
||||||
|
|
||||||
|
(defn list! [schema instances new-form req]
|
||||||
|
(view/layout!
|
||||||
|
:request req
|
||||||
|
:content
|
||||||
|
[[:h1 "All Instances of schema "
|
||||||
|
[:span.schema-title__name (h (:name schema))]]
|
||||||
|
[:h1 "New Instance"]
|
||||||
|
(hform/form-to [:post (path :instance-new)]
|
||||||
|
(form/render-widgets new-form {} req)
|
||||||
|
(hform/hidden-field "schema-uuid"
|
||||||
|
(:uuid schema))
|
||||||
|
(hform/submit-button "Create!"))
|
||||||
|
[:table
|
||||||
|
[:thead
|
||||||
|
[:tr
|
||||||
|
[:th "Name"]
|
||||||
|
[:th "Updated"]
|
||||||
|
[:th "Created"]]]
|
||||||
|
[:tbody
|
||||||
|
(for [instance instances]
|
||||||
|
[:tr
|
||||||
|
[:td
|
||||||
|
[:a {:href (path :instance-show instance)}
|
||||||
|
(h (:name instance))]]
|
||||||
|
[:td (prettify-dt (:updated_at instance))]
|
||||||
|
[:td (prettify-dt (:created_at instance))]])]]]))
|
||||||
|
|
||||||
|
(defn list-starred [instances req]
|
||||||
|
(view/layout!
|
||||||
|
:request req
|
||||||
|
:content
|
||||||
|
[[:h1 "Starred instances"]
|
||||||
|
[:table
|
||||||
|
[:thead
|
||||||
|
[:tr
|
||||||
|
[:th "Name"]
|
||||||
|
[:th "Starred"]
|
||||||
|
[:th "Updated"]
|
||||||
|
[:th "Created"]]]
|
||||||
|
[:tbody
|
||||||
|
(for [instance instances]
|
||||||
|
[:tr
|
||||||
|
[:td
|
||||||
|
[:a {:href (path :instance-show instance)}
|
||||||
|
(h (:name instance))]]
|
||||||
|
[:td (prettify-dt (:starred_at instance))]
|
||||||
|
[:td (prettify-dt (:updated_at instance))]
|
||||||
|
[:td (prettify-dt (:created_at instance))]])]]]))
|
||||||
|
|
||||||
|
(defn show! [instance schemas req]
|
||||||
|
(view/layout!
|
||||||
|
:request req
|
||||||
|
:content
|
||||||
|
[[:h1
|
||||||
|
(if (:starred instance)
|
||||||
|
(hform/form-to {:class "inline"}
|
||||||
|
[:delete (path :instance-mark-starred instance)]
|
||||||
|
(anti-forgery-field)
|
||||||
|
(hform/submit-button "★"))
|
||||||
|
(hform/form-to {:class "inline"}
|
||||||
|
[:post (path :instance-mark-starred instance)]
|
||||||
|
(anti-forgery-field)
|
||||||
|
(hform/submit-button "☆")))
|
||||||
|
" "
|
||||||
|
(h (-> instance :schema :name))
|
||||||
|
" "
|
||||||
|
[:small (h (:name instance))]]
|
||||||
|
[:p [:small
|
||||||
|
[:a {:href (path :instance-list
|
||||||
|
{:schema-uuid (-> instance :schema :uuid)})}
|
||||||
|
"Back to List"]
|
||||||
|
" | "
|
||||||
|
[:a {:href (path :instance-edit-form instance)}
|
||||||
|
"Edit Instance"]
|
||||||
|
" | "
|
||||||
|
[:a {:href (path :vis-explore {:instance-uuid (:uuid instance)})}
|
||||||
|
"Explore from here"]]]
|
||||||
|
(when (seq (:tags instance))
|
||||||
|
[:section.tags
|
||||||
|
(view-tag/tag-list (:tags instance))])
|
||||||
|
(when (seq (:properties instance))
|
||||||
|
[:section.properties
|
||||||
|
[:h2 "Properties"]
|
||||||
|
(for [prop (:properties instance)
|
||||||
|
:let [attr (:attribute prop)
|
||||||
|
type (:type attr)
|
||||||
|
render-fn (case type
|
||||||
|
"date" #(str (prettify-dt %))
|
||||||
|
"markdown" md/md-to-html-string
|
||||||
|
#(str "<p>" % "</p>"))]]
|
||||||
|
(list [:h3 (h (:name attr))]
|
||||||
|
[:div {:class (str "instance-content "
|
||||||
|
"attr-type-" type)}
|
||||||
|
(render-fn (:value prop))]))])
|
||||||
|
(when (or (seq (:links-out instance))
|
||||||
|
(seq (:links-in instance)))
|
||||||
|
[:section.visualisation
|
||||||
|
[:h2 "Visualisation"]
|
||||||
|
[:p (viz/single-instance instance)]])
|
||||||
|
(when (seq (:links-out instance))
|
||||||
|
[:section.links-out
|
||||||
|
[:h2 "Outgoing Links"]
|
||||||
|
[:table
|
||||||
|
[:thead
|
||||||
|
[:tr
|
||||||
|
[:th "Name"]
|
||||||
|
[:th "Instance"]
|
||||||
|
[:th "Schema"]
|
||||||
|
[:th "Created"]]]
|
||||||
|
[:tbody
|
||||||
|
(for [{:keys [link target schema]} (:links-out instance)
|
||||||
|
:let [name (:name link)
|
||||||
|
empty (empty? name)
|
||||||
|
name (if empty [:i "empty"] (h name))]]
|
||||||
|
[:tr
|
||||||
|
[:td name]
|
||||||
|
[:td [:a {:href (path :instance-show target)}
|
||||||
|
(h (:name target))]]
|
||||||
|
[:td [:a {:href (path :instance-list
|
||||||
|
{:schema-uuid (:uuid schema)})}
|
||||||
|
(h (:name schema))]]
|
||||||
|
[:td (prettify-dt (:created_at link))]])]]])
|
||||||
|
(when (seq (:links-in instance))
|
||||||
|
[:section.links-in
|
||||||
|
[:h2 "Incoming Links"]
|
||||||
|
[:table
|
||||||
|
[:thead
|
||||||
|
[:tr
|
||||||
|
[:th "Name"]
|
||||||
|
[:th "Instance"]
|
||||||
|
[:th "Schema"]
|
||||||
|
[:th "Created"]]]
|
||||||
|
[:tbody
|
||||||
|
(for [{:keys [link source schema]} (:links-in instance)
|
||||||
|
:let [name (:name link)
|
||||||
|
empty (empty? name)
|
||||||
|
name (if empty [:i "empty"] (h name))]]
|
||||||
|
[:tr
|
||||||
|
[:td name]
|
||||||
|
[:td [:a {:href (path :instance-show source)}
|
||||||
|
(h (:name source))]]
|
||||||
|
[:td [:a {:href (path :instance-list
|
||||||
|
{:schema-uuid (:uuid schema)})}
|
||||||
|
(h (:name schema))]]
|
||||||
|
[:td (prettify-dt (:created_at link))]])]]])
|
||||||
|
[:section.quick-edits
|
||||||
|
[:h2 "Quick edits"]
|
||||||
|
[:section.link-instance
|
||||||
|
[:h3 "Link Instance with Instance of Schema..."]
|
||||||
|
[:ul
|
||||||
|
(for [schema schemas]
|
||||||
|
[:li
|
||||||
|
[:a {:href (path :instance-link-selection
|
||||||
|
{:uuid (:uuid instance)
|
||||||
|
:schema-uuid (:uuid schema)})}
|
||||||
|
(h (:name schema))]])]]
|
||||||
|
[:section.tag-instance
|
||||||
|
[:h3 "Add or create Tags"]
|
||||||
|
(view-tag/new-tag-form instance)]]]))
|
||||||
|
|
||||||
|
(defn edit! [instance form form-data schemas req]
|
||||||
|
(view/layout!
|
||||||
|
:request req
|
||||||
|
:content
|
||||||
|
[[:h1
|
||||||
|
(h (-> instance :schema :name))
|
||||||
|
" "
|
||||||
|
[:small (h (:name instance))]]
|
||||||
|
[:p [:small
|
||||||
|
[:a {:href (path :instance-list
|
||||||
|
{:schema-uuid (-> instance :schema :uuid)})}
|
||||||
|
"Back to List"]
|
||||||
|
" | "
|
||||||
|
[:a {:href (path :instance-show instance)}
|
||||||
|
"Back to Instance"]]]
|
||||||
|
[:section.edit-instance
|
||||||
|
[:h2 "Edit Instance"]
|
||||||
|
(hform/form-to [:post (path :instance-edit instance)]
|
||||||
|
(form/render-widgets form form-data req)
|
||||||
|
(hform/submit-button "Edit!"))
|
||||||
|
(hform/form-to [:delete (path :instance-delete instance)]
|
||||||
|
(anti-forgery-field)
|
||||||
|
(view/delete-btn))]
|
||||||
|
(when (seq (:links-out instance))
|
||||||
|
[:section.links-out
|
||||||
|
[:h2 "Outgoing Links"]
|
||||||
|
[:table
|
||||||
|
[:thead
|
||||||
|
[:tr
|
||||||
|
[:th "Name"]
|
||||||
|
[:th "Instance"]
|
||||||
|
[:th "Schema"]
|
||||||
|
[:th "Created"]
|
||||||
|
[:th]]]
|
||||||
|
[:tbody
|
||||||
|
(for [{:keys [link target schema]} (:links-out instance)
|
||||||
|
:let [name (:name link)
|
||||||
|
empty (empty? name)
|
||||||
|
name (if empty [:i "empty"] (h name))]]
|
||||||
|
[:tr
|
||||||
|
[:td name]
|
||||||
|
[:td [:a {:href (path :instance-show target)}
|
||||||
|
(h (:name target))]]
|
||||||
|
[:td [:a {:href (path :instance-list
|
||||||
|
{:schema-uuid (:uuid schema)})}
|
||||||
|
(h (:name schema))]]
|
||||||
|
[:td (prettify-dt (:created_at link))]
|
||||||
|
[:td (hform/form-to [:delete (path :instance-link-delete
|
||||||
|
{:uuid (:uuid instance)
|
||||||
|
:link-uuid (:uuid link)})]
|
||||||
|
(anti-forgery-field)
|
||||||
|
(view/delete-btn))]])]]])
|
||||||
|
(when (seq (:tags instance))
|
||||||
|
[:section.tags
|
||||||
|
[:h2 "Tags"]
|
||||||
|
(view-tag/tag-table instance)])
|
||||||
|
[:section.link-instance
|
||||||
|
[:h2 "Link Instance with Instance of Schema..."]
|
||||||
|
[:ul
|
||||||
|
(for [schema schemas]
|
||||||
|
[:li
|
||||||
|
[:a {:href (path :instance-link-selection
|
||||||
|
{:uuid (:uuid instance)
|
||||||
|
:schema-uuid (:uuid schema)})}
|
||||||
|
(h (:name schema))]])]]]))
|
||||||
|
|
||||||
|
(defn link-selection [instance schema form req]
|
||||||
|
(view/layout!
|
||||||
|
:request req
|
||||||
|
:content
|
||||||
|
[[:h1
|
||||||
|
[:small "Link " (-> instance :schema :name) " "]
|
||||||
|
(h (:name instance))
|
||||||
|
[:small " with "]
|
||||||
|
(h (:name schema))]
|
||||||
|
(hform/form-to [:post (path :instance-link-create
|
||||||
|
{:uuid (:uuid instance)
|
||||||
|
:schema-uuid (:uuid schema)})]
|
||||||
|
(form/render-widgets form nil req)
|
||||||
|
(hform/submit-button "Link!"))]))
|
@ -1,56 +0,0 @@
|
|||||||
(ns wanijo.instance.view.bulk-link-selection
|
|
||||||
(:require [hiccup.form :as hform]
|
|
||||||
[hiccup.core :refer [h]]
|
|
||||||
[wanijo.infra.view :as view]
|
|
||||||
[wanijo.infra.routing :refer [path]]
|
|
||||||
[wanijo.infra.time :refer [prettify-dt]]
|
|
||||||
[wanijo.instance.view.view
|
|
||||||
:refer [req-attrs-headings
|
|
||||||
req-attrs-cells
|
|
||||||
tags-for-search]]
|
|
||||||
[formulare.core :as form]
|
|
||||||
[ring.util.anti-forgery :refer [anti-forgery-field]]))
|
|
||||||
|
|
||||||
(defn bulk-link-selection [instance forms req]
|
|
||||||
(view/layout
|
|
||||||
:request req
|
|
||||||
:content
|
|
||||||
[[:h1
|
|
||||||
[:small "Link " (-> instance :schema :name h) " "]
|
|
||||||
(h (:name instance))
|
|
||||||
[:small " with..."]]
|
|
||||||
(hform/form-to
|
|
||||||
{:class "no-grid"}
|
|
||||||
[:post (path :instance-bulk-link-create instance)]
|
|
||||||
(anti-forgery-field)
|
|
||||||
(hform/hidden-field "source-uuid" (:uuid instance))
|
|
||||||
(for [{:keys [schema instances]} forms]
|
|
||||||
(list
|
|
||||||
[:h2 "Schema " (h (:name schema))]
|
|
||||||
(let [ident (str "name[" (:uuid schema) "]")]
|
|
||||||
[:div.sub-form
|
|
||||||
[:label {:for ident}
|
|
||||||
"Link name"]
|
|
||||||
[:input {:name ident :id ident}]])
|
|
||||||
[:table
|
|
||||||
[:thead
|
|
||||||
[:tr
|
|
||||||
[:th "Selection"]
|
|
||||||
[:th "Name"]
|
|
||||||
(req-attrs-headings schema)
|
|
||||||
[:th "Updated"]
|
|
||||||
[:th "Created"]]]
|
|
||||||
[:tbody
|
|
||||||
(for [inst instances]
|
|
||||||
[:tr
|
|
||||||
[:td {:style "text-align: center;"}
|
|
||||||
[:input {:type "checkbox"
|
|
||||||
:name (str "instances[" (:uuid schema) "]")
|
|
||||||
:value (:uuid inst)}]]
|
|
||||||
[:td (h (:name inst))
|
|
||||||
(tags-for-search inst)]
|
|
||||||
(req-attrs-cells schema inst)
|
|
||||||
[:td (-> inst :updated_at prettify-dt)]
|
|
||||||
[:td (-> inst :created_at prettify-dt)]])]]))
|
|
||||||
[:h2 "Actions"]
|
|
||||||
(hform/submit-button "Create links!"))]))
|
|
@ -1,78 +0,0 @@
|
|||||||
(ns wanijo.instance.view.edit
|
|
||||||
(:require [hiccup.form :as hform]
|
|
||||||
[hiccup.core :refer [h]]
|
|
||||||
[ring.util.anti-forgery :refer [anti-forgery-field]]
|
|
||||||
[wanijo.infra.view :as view]
|
|
||||||
[wanijo.infra.routing :refer [path]]
|
|
||||||
[wanijo.infra.time :refer [prettify-dt]]
|
|
||||||
[wanijo.tag.view :as view-tag]
|
|
||||||
[formulare.core :as form]))
|
|
||||||
|
|
||||||
(defn edit [instance form form-data schemas req]
|
|
||||||
(view/layout
|
|
||||||
:request req
|
|
||||||
:title (str (:name instance) " - " (-> instance :schema :name))
|
|
||||||
:content
|
|
||||||
[[:h1
|
|
||||||
(h (-> instance :schema :name))
|
|
||||||
" "
|
|
||||||
[:small (h (:name instance))]]
|
|
||||||
[:p [:small
|
|
||||||
[:a {:href (path :instance-list
|
|
||||||
{:schema-uuid (-> instance :schema :uuid)})}
|
|
||||||
"Back to List"]
|
|
||||||
" | "
|
|
||||||
[:a {:href (path :instance-show instance)}
|
|
||||||
"Back to Instance"]]]
|
|
||||||
[:section.edit-instance
|
|
||||||
[:h2 "Edit Instance"]
|
|
||||||
[:form {:method "post"
|
|
||||||
:action (path :instance-edit instance)
|
|
||||||
:enctype "multipart/form-data"}
|
|
||||||
(form/render-widgets form form-data req)
|
|
||||||
(hform/submit-button "Edit!")]
|
|
||||||
(hform/form-to [:delete (path :instance-delete instance)]
|
|
||||||
(anti-forgery-field)
|
|
||||||
(view/delete-btn))]
|
|
||||||
(when (seq (:links-out instance))
|
|
||||||
[:section.links-out
|
|
||||||
[:h2 "Outgoing Links"]
|
|
||||||
[:table
|
|
||||||
[:thead
|
|
||||||
[:tr
|
|
||||||
[:th "Name"]
|
|
||||||
[:th "Instance"]
|
|
||||||
[:th "Schema"]
|
|
||||||
[:th "Created"]
|
|
||||||
[:th]]]
|
|
||||||
[:tbody
|
|
||||||
(for [{:keys [link target schema]} (:links-out instance)
|
|
||||||
:let [name (:name link)
|
|
||||||
empty (empty? name)
|
|
||||||
name (if empty [:i "empty"] (h name))]]
|
|
||||||
[:tr
|
|
||||||
[:td name]
|
|
||||||
[:td [:a {:href (path :instance-show target)}
|
|
||||||
(h (:name target))]]
|
|
||||||
[:td [:a {:href (path :instance-list
|
|
||||||
{:schema-uuid (:uuid schema)})}
|
|
||||||
(h (:name schema))]]
|
|
||||||
[:td (prettify-dt (:created_at link))]
|
|
||||||
[:td (hform/form-to [:delete (path :instance-link-delete
|
|
||||||
{:uuid (:uuid instance)
|
|
||||||
:link-uuid (:uuid link)})]
|
|
||||||
(anti-forgery-field)
|
|
||||||
(view/delete-btn))]])]]])
|
|
||||||
(when (seq (:tags instance))
|
|
||||||
[:section.tags
|
|
||||||
[:h2 "Tags"]
|
|
||||||
(view-tag/tag-table instance)])
|
|
||||||
[:section.link-instance
|
|
||||||
[:h2 "Link Instance with Instance of Schema..."]
|
|
||||||
[:ul
|
|
||||||
(for [schema schemas]
|
|
||||||
[:li
|
|
||||||
[:a {:href (path :instance-link-selection
|
|
||||||
{:uuid (:uuid instance)
|
|
||||||
:schema-uuid (:uuid schema)})}
|
|
||||||
(h (:name schema))]])]]]))
|
|
@ -1,39 +0,0 @@
|
|||||||
(ns wanijo.instance.view.instances
|
|
||||||
(:require [hiccup.form :as hform]
|
|
||||||
[hiccup.core :refer [h]]
|
|
||||||
[formulare.core :as form]
|
|
||||||
[wanijo.instance.view.view :as view-instance]
|
|
||||||
[wanijo.infra.view :as view]
|
|
||||||
[wanijo.infra.routing :refer [path]]
|
|
||||||
[wanijo.infra.time :refer [prettify-dt]]))
|
|
||||||
|
|
||||||
(defn instances [schema instances new-form req]
|
|
||||||
(view/layout
|
|
||||||
:request req
|
|
||||||
:title (:name schema)
|
|
||||||
:content
|
|
||||||
[[:h1 "All Instances of schema "
|
|
||||||
[:span.schema-title__name (h (:name schema))]]
|
|
||||||
[:h1 "New Instance"]
|
|
||||||
(hform/form-to [:post (path :instance-new)]
|
|
||||||
(form/render-widgets new-form {} req)
|
|
||||||
(hform/hidden-field "schema-uuid"
|
|
||||||
(:uuid schema))
|
|
||||||
(hform/submit-button "Create!"))
|
|
||||||
[:table
|
|
||||||
[:thead
|
|
||||||
[:tr
|
|
||||||
[:th "Name"]
|
|
||||||
(view-instance/req-attrs-headings schema)
|
|
||||||
[:th "Updated"]
|
|
||||||
[:th "Created"]]]
|
|
||||||
[:tbody
|
|
||||||
(for [instance instances]
|
|
||||||
[:tr
|
|
||||||
[:td
|
|
||||||
[:a {:href (path :instance-show instance)}
|
|
||||||
(h (:name instance))]
|
|
||||||
(view-instance/tags-for-search instance)]
|
|
||||||
(view-instance/req-attrs-cells schema instance)
|
|
||||||
[:td (prettify-dt (:updated_at instance))]
|
|
||||||
[:td (prettify-dt (:created_at instance))]])]]]))
|
|
@ -1,22 +0,0 @@
|
|||||||
(ns wanijo.instance.view.link-selection
|
|
||||||
(:require [hiccup.form :as hform]
|
|
||||||
[hiccup.core :refer [h]]
|
|
||||||
[wanijo.infra.view :as view]
|
|
||||||
[wanijo.infra.routing :refer [path]]
|
|
||||||
[formulare.core :as form]))
|
|
||||||
|
|
||||||
(defn link-selection [instance schema form req]
|
|
||||||
(view/layout
|
|
||||||
:request req
|
|
||||||
:title (str (:name instance) " - " (-> instance :schema :name))
|
|
||||||
:content
|
|
||||||
[[:h1
|
|
||||||
[:small "Link " (-> instance :schema :name h) " "]
|
|
||||||
(h (:name instance))
|
|
||||||
[:small " with "]
|
|
||||||
(h (:name schema))]
|
|
||||||
(hform/form-to [:post (path :instance-link-create
|
|
||||||
{:uuid (:uuid instance)
|
|
||||||
:schema-uuid (:uuid schema)})]
|
|
||||||
(form/render-widgets form nil req)
|
|
||||||
(hform/submit-button "Link!"))]))
|
|
@ -1,112 +0,0 @@
|
|||||||
(ns wanijo.instance.view.show
|
|
||||||
(:require [hiccup.form :as hform]
|
|
||||||
[hiccup.core :refer [h]]
|
|
||||||
[ring.util.anti-forgery :refer [anti-forgery-field]]
|
|
||||||
[wanijo.infra.view :as view]
|
|
||||||
[wanijo.infra.routing :refer [path]]
|
|
||||||
[wanijo.infra.time :refer [prettify-dt]]
|
|
||||||
[wanijo.instance.view.view :as view-instance]
|
|
||||||
[wanijo.tag.view :as view-tag]
|
|
||||||
[markdown.core :as md]
|
|
||||||
[wanijo.visualisation.viz :as viz]))
|
|
||||||
|
|
||||||
(defn links-table [heading direction instance]
|
|
||||||
[:section.links-in
|
|
||||||
[:h2 (h heading)]
|
|
||||||
[:table
|
|
||||||
[:thead
|
|
||||||
[:tr
|
|
||||||
[:th "Name"]
|
|
||||||
[:th "Instance"]
|
|
||||||
[:th "Schema"]
|
|
||||||
[:th "Created"]]]
|
|
||||||
[:tbody
|
|
||||||
(for [{:keys [link source schema target] :as row} (direction instance)
|
|
||||||
:let [name (:name link)
|
|
||||||
empty (empty? name)
|
|
||||||
name (if empty [:i "empty"] (h name))
|
|
||||||
other (or source target)]]
|
|
||||||
[:tr
|
|
||||||
[:td name
|
|
||||||
(view-instance/tags-for-search row)]
|
|
||||||
[:td [:a {:href (path :instance-show other)}
|
|
||||||
(h (:name other))]]
|
|
||||||
[:td [:a {:href (path :instance-list
|
|
||||||
{:schema-uuid (:uuid schema)})}
|
|
||||||
(h (:name schema))]]
|
|
||||||
[:td (prettify-dt (:created_at link))]])]]])
|
|
||||||
|
|
||||||
(defn show [instance schemas req]
|
|
||||||
(view/layout
|
|
||||||
:request req
|
|
||||||
:title (str (:name instance) " - " (-> instance :schema :name))
|
|
||||||
:content
|
|
||||||
[[:h1
|
|
||||||
(if (:starred instance)
|
|
||||||
(hform/form-to {:class "inline"}
|
|
||||||
[:delete (path :instance-mark-starred instance)]
|
|
||||||
(anti-forgery-field)
|
|
||||||
(hform/submit-button "★"))
|
|
||||||
(hform/form-to {:class "inline"}
|
|
||||||
[:post (path :instance-mark-starred instance)]
|
|
||||||
(anti-forgery-field)
|
|
||||||
(hform/submit-button "☆")))
|
|
||||||
" "
|
|
||||||
(h (-> instance :schema :name))
|
|
||||||
" "
|
|
||||||
[:small (h (:name instance))]]
|
|
||||||
[:p [:small
|
|
||||||
[:a {:href (path :instance-list
|
|
||||||
{:schema-uuid (-> instance :schema :uuid)})}
|
|
||||||
"Back to List"]
|
|
||||||
" | "
|
|
||||||
[:a {:href (path :instance-edit-form instance)}
|
|
||||||
"Edit Instance"]
|
|
||||||
" | "
|
|
||||||
[:a {:href (path :vis-explore {:instance-uuid (:uuid instance)})}
|
|
||||||
"Explore from here"]
|
|
||||||
" | "
|
|
||||||
[:a {:href "#quick-edits"}
|
|
||||||
"Quick edits"]]]
|
|
||||||
(when (seq (:tags instance))
|
|
||||||
[:section.tags
|
|
||||||
(view-tag/tag-list (:tags instance))])
|
|
||||||
(when (seq (:properties instance))
|
|
||||||
[:section.properties
|
|
||||||
[:h2 "Properties"]
|
|
||||||
(for [prop (:properties instance)
|
|
||||||
:let [attr (:attribute prop)
|
|
||||||
type (:type attr)
|
|
||||||
render-fn (case type
|
|
||||||
"date" #(str (prettify-dt %))
|
|
||||||
"markdown" md/md-to-html-string
|
|
||||||
#(str "<p>" % "</p>"))]]
|
|
||||||
(list [:h3 (h (:name attr))]
|
|
||||||
[:div {:class (str "instance-content "
|
|
||||||
"attr-type-" type)}
|
|
||||||
(render-fn (:value prop))]))])
|
|
||||||
(when (or (seq (:links-out instance))
|
|
||||||
(seq (:links-in instance)))
|
|
||||||
[:section.visualisation
|
|
||||||
[:h2 "Visualisation"]
|
|
||||||
[:p (viz/single-instance instance)]])
|
|
||||||
(when (seq (:links-out instance))
|
|
||||||
(links-table "Outgoing links" :links-out instance))
|
|
||||||
(when (seq (:links-in instance))
|
|
||||||
(links-table "Incoming links" :links-in instance))
|
|
||||||
[:section.quick-edits
|
|
||||||
[:h2 {:id "quick-edits"} "Quick edits"]
|
|
||||||
[:section.link-instance
|
|
||||||
[:h3 "Link Instance with Instance of Schema..."]
|
|
||||||
[:ul
|
|
||||||
(for [schema schemas]
|
|
||||||
[:li
|
|
||||||
[:a {:href (path :instance-link-selection
|
|
||||||
{:uuid (:uuid instance)
|
|
||||||
:schema-uuid (:uuid schema)})}
|
|
||||||
(h (:name schema))]])]
|
|
||||||
[:a {:href (path :instance-bulk-link-selection instance)}
|
|
||||||
"Bulk create links"]]
|
|
||||||
[:section.tag-instance
|
|
||||||
[:h3 "Add or create Tags"]
|
|
||||||
(view-tag/new-tag-form instance)]]]))
|
|
@ -1,27 +0,0 @@
|
|||||||
(ns wanijo.instance.view.starred
|
|
||||||
(:require [hiccup.core :refer [h]]
|
|
||||||
[wanijo.infra.view :as view]
|
|
||||||
[wanijo.infra.routing :refer [path]]
|
|
||||||
[wanijo.infra.time :refer [prettify-dt]]))
|
|
||||||
|
|
||||||
(defn starred [instances req]
|
|
||||||
(view/layout
|
|
||||||
:request req
|
|
||||||
:content
|
|
||||||
[[:h1 "Starred instances"]
|
|
||||||
[:table
|
|
||||||
[:thead
|
|
||||||
[:tr
|
|
||||||
[:th "Name"]
|
|
||||||
[:th "Starred"]
|
|
||||||
[:th "Updated"]
|
|
||||||
[:th "Created"]]]
|
|
||||||
[:tbody
|
|
||||||
(for [instance instances]
|
|
||||||
[:tr
|
|
||||||
[:td
|
|
||||||
[:a {:href (path :instance-show instance)}
|
|
||||||
(h (:name instance))]]
|
|
||||||
[:td (prettify-dt (:starred_at instance))]
|
|
||||||
[:td (prettify-dt (:updated_at instance))]
|
|
||||||
[:td (prettify-dt (:created_at instance))]])]]]))
|
|
@ -1,21 +0,0 @@
|
|||||||
(ns wanijo.instance.view.view
|
|
||||||
(:require [hiccup.core :refer [h]]))
|
|
||||||
|
|
||||||
(defn tags-for-search [{tags :tags}]
|
|
||||||
[:span.tags-for-search
|
|
||||||
(reduce #(str %1 ":" (h (:name %2))) "" tags)])
|
|
||||||
|
|
||||||
(defn req-attrs-headings [{:keys [req-attrs]}]
|
|
||||||
(map (fn [attr] [:th (h (:name attr))])
|
|
||||||
req-attrs))
|
|
||||||
|
|
||||||
(defn req-attrs-cells [{:keys [req-attrs]}
|
|
||||||
{:keys [properties]}]
|
|
||||||
(map (fn [{attr-uuid :uuid}]
|
|
||||||
[:td (->> properties
|
|
||||||
(filter #(= attr-uuid
|
|
||||||
(-> % :attribute :uuid)))
|
|
||||||
first
|
|
||||||
:value
|
|
||||||
h)])
|
|
||||||
req-attrs))
|
|
@ -1,37 +0,0 @@
|
|||||||
(ns wanijo.link.db
|
|
||||||
(:require [clojure.spec.alpha :as spec]
|
|
||||||
[wanijo.specs :as specs]
|
|
||||||
[wanijo.infra.neo4j :as neo4j]))
|
|
||||||
|
|
||||||
(spec/def ::link
|
|
||||||
(spec/keys :req-un [::neo4j/uuid
|
|
||||||
::specs/created_at
|
|
||||||
::name]))
|
|
||||||
|
|
||||||
(neo4j/defquery create
|
|
||||||
"MATCH (i:instance {uuid: $from}),
|
|
||||||
(t:instance {uuid: $target})
|
|
||||||
CREATE (i)-[l:link]->(t)
|
|
||||||
SET l.created_at = $created_at,
|
|
||||||
l.name = $name,
|
|
||||||
l.created_by = $by,
|
|
||||||
l.uuid = $uuid")
|
|
||||||
(defn create! [{:keys [from name to by]}]
|
|
||||||
(let [tuples (map (fn [target-uuid]
|
|
||||||
[create
|
|
||||||
{:from from
|
|
||||||
:by by
|
|
||||||
:target target-uuid
|
|
||||||
:uuid (neo4j/uuid)
|
|
||||||
:created_at (neo4j/now-str)
|
|
||||||
:name name}])
|
|
||||||
to)]
|
|
||||||
(apply neo4j/exec-queries! tuples)))
|
|
||||||
|
|
||||||
(neo4j/defquery delete
|
|
||||||
"MATCH (:instance)-[l:link]-(:instance)
|
|
||||||
WHERE l.uuid = {uuid}
|
|
||||||
DELETE l")
|
|
||||||
(defn delete! [uuid]
|
|
||||||
(neo4j/exec-query! delete
|
|
||||||
{:uuid uuid}))
|
|
@ -1,207 +0,0 @@
|
|||||||
(ns wanijo.schema.db
|
|
||||||
(:require [wanijo.infra.neo4j :as neo4j]
|
|
||||||
[wanijo.schema.domain :as domain]
|
|
||||||
[clojure.spec.alpha :as spec]))
|
|
||||||
|
|
||||||
(neo4j/defquery all-readable-by
|
|
||||||
"MATCH (s:schema)-[p:permission]-(u:user)
|
|
||||||
WHERE u.uuid = $uuid
|
|
||||||
AND p.type IN ['read', 'write']
|
|
||||||
RETURN s
|
|
||||||
ORDER BY s.name")
|
|
||||||
(defn all-readable-by! [user-uuid]
|
|
||||||
(map :s
|
|
||||||
(neo4j/exec-query!
|
|
||||||
all-readable-by
|
|
||||||
{:uuid user-uuid})))
|
|
||||||
|
|
||||||
(neo4j/defquery all
|
|
||||||
"MATCH (s:schema)
|
|
||||||
RETURN s
|
|
||||||
ORDER BY s.name")
|
|
||||||
(defn all! []
|
|
||||||
(map :s
|
|
||||||
(neo4j/exec-query! all {})))
|
|
||||||
|
|
||||||
(neo4j/defquery create-new
|
|
||||||
"MATCH (u:user)
|
|
||||||
WHERE u.uuid = $u_uuid
|
|
||||||
CREATE (s:schema)-[:created_by]->(u)
|
|
||||||
SET s.name = $name
|
|
||||||
SET s.uuid = $s_uuid
|
|
||||||
SET s.created_at = $created_at
|
|
||||||
WITH u, s
|
|
||||||
CREATE (u)-[:permission {type:'write'}]->(s)
|
|
||||||
RETURN s")
|
|
||||||
(defn create-new! [schema-name user-uuid]
|
|
||||||
(->>
|
|
||||||
(neo4j/exec-query!
|
|
||||||
create-new
|
|
||||||
{:u_uuid user-uuid
|
|
||||||
:name schema-name
|
|
||||||
:s_uuid (neo4j/uuid)
|
|
||||||
:created_at (neo4j/now-str)})
|
|
||||||
first
|
|
||||||
:uuid))
|
|
||||||
|
|
||||||
(neo4j/defquery find-by-uuid
|
|
||||||
"MATCH (s:schema)
|
|
||||||
WHERE s.uuid = $uuid
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(s)<-[:of]-(a:attribute)
|
|
||||||
WHERE a.required = 1
|
|
||||||
RETURN s, a
|
|
||||||
ORDER BY a.name")
|
|
||||||
(defn find-by-uuid! [uuid]
|
|
||||||
{:post [(spec/assert ::domain/schema-with-req-attrs %)]}
|
|
||||||
(let [result (neo4j/exec-query!
|
|
||||||
find-by-uuid
|
|
||||||
{:uuid uuid})
|
|
||||||
schema (:s (first result))]
|
|
||||||
(when schema
|
|
||||||
(assoc schema
|
|
||||||
:req-attrs (map :a result)))))
|
|
||||||
|
|
||||||
(neo4j/defquery schema-permissions
|
|
||||||
"MATCH (s:schema {uuid: $schema_uuid})
|
|
||||||
RETURN
|
|
||||||
EXISTS((:user {uuid: $user_uuid})
|
|
||||||
-[:permission {type: $type}]-
|
|
||||||
(s))
|
|
||||||
OR
|
|
||||||
EXISTS((:user {uuid : $user_uuid})
|
|
||||||
-[:permission {type: 'write'}]-
|
|
||||||
(s))
|
|
||||||
AS user_has_permission,
|
|
||||||
NOT EXISTS((:user)-[:permission]-(s)) AS is_public")
|
|
||||||
(defn has-user-permission? [perm-type schema-uuid user-uuid]
|
|
||||||
(let [perms (first
|
|
||||||
(neo4j/exec-query! schema-permissions
|
|
||||||
{:schema_uuid schema-uuid
|
|
||||||
:user_uuid user-uuid
|
|
||||||
:type perm-type}))]
|
|
||||||
(domain/has-user-permission? perms)))
|
|
||||||
(defn has-user-write-permissions? [schema-uuid user-uuid]
|
|
||||||
(has-user-permission? "write" schema-uuid user-uuid))
|
|
||||||
(defn has-user-read-permissions? [schema-uuid user-uuid]
|
|
||||||
(has-user-permission? "read" schema-uuid user-uuid))
|
|
||||||
|
|
||||||
(neo4j/defquery accessible-schemas
|
|
||||||
"MATCH (s:schema),
|
|
||||||
(u:user {uuid: $user_uuid})
|
|
||||||
WHERE EXISTS((u)-[:permission {type:'read'}]->(s))
|
|
||||||
OR NOT EXISTS((:user)-[:permission {type:'read'}]->(s))
|
|
||||||
WITH s
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(s)<-[:of]-(a:attribute)
|
|
||||||
WHERE a.required = 1
|
|
||||||
RETURN s, COLLECT(a) AS a
|
|
||||||
ORDER BY s.name")
|
|
||||||
(defn accessible-schemas! [user-uuid]
|
|
||||||
{:post [(spec/assert ::domain/schema-with-req-attrs %)]}
|
|
||||||
(map (fn [{s :s a :a}]
|
|
||||||
(assoc s
|
|
||||||
:req-attrs (sort-by :name a)))
|
|
||||||
(neo4j/exec-query! accessible-schemas
|
|
||||||
{:user_uuid user-uuid})))
|
|
||||||
|
|
||||||
(neo4j/defquery delete
|
|
||||||
"MATCH (s:schema {uuid: $uuid})
|
|
||||||
WITH s
|
|
||||||
OPTIONAL MATCH (s)--(a:attribute)-[cb:created_by]-(:user)
|
|
||||||
DELETE cb, a
|
|
||||||
WITH s
|
|
||||||
MATCH (s)-[c]-()
|
|
||||||
DELETE c, s")
|
|
||||||
(defn delete! [uuid]
|
|
||||||
(neo4j/exec-query!
|
|
||||||
delete
|
|
||||||
{:uuid uuid}))
|
|
||||||
|
|
||||||
(neo4j/defquery edit
|
|
||||||
"MATCH (s:schema)
|
|
||||||
WHERE s.uuid = $uuid
|
|
||||||
SET s.name = $name")
|
|
||||||
(defn edit! [schema]
|
|
||||||
(neo4j/exec-query!
|
|
||||||
edit
|
|
||||||
schema))
|
|
||||||
|
|
||||||
(neo4j/defquery assigned-users
|
|
||||||
"MATCH (s:schema)-[p:permission]-(u:user)
|
|
||||||
WHERE s.uuid = $uuid
|
|
||||||
RETURN u, p
|
|
||||||
ORDER BY u.ident")
|
|
||||||
(defn assigned-users! [uuid]
|
|
||||||
(neo4j/exec-query!
|
|
||||||
assigned-users
|
|
||||||
{:uuid uuid}))
|
|
||||||
|
|
||||||
(neo4j/defquery assigned-schemas
|
|
||||||
"MATCH (s1:schema)-[p:permission]-(s2:schema)
|
|
||||||
WHERE s1.uuid = $uuid
|
|
||||||
RETURN s2
|
|
||||||
ORDER BY s2.name")
|
|
||||||
(defn assigned-schemas! [uuid]
|
|
||||||
(neo4j/exec-query!
|
|
||||||
assigned-schemas
|
|
||||||
{:uuid uuid}))
|
|
||||||
|
|
||||||
(defn find-with-assigned-entities! [uuid]
|
|
||||||
(let [users (reduce #(case (-> %2 :p :type)
|
|
||||||
"write" (update %1 :write conj (-> %2 :u :uuid))
|
|
||||||
"read" (update %1 :read conj (-> %2 :u :uuid))
|
|
||||||
%1)
|
|
||||||
{:write []
|
|
||||||
:read []}
|
|
||||||
(assigned-users! uuid))
|
|
||||||
schemas (map #(-> % :s2 :uuid) (assigned-schemas! uuid))]
|
|
||||||
(assoc (find-by-uuid! uuid)
|
|
||||||
:assigned-read-users (:read users)
|
|
||||||
:assigned-write-users (:write users)
|
|
||||||
:assigned-schemas schemas)))
|
|
||||||
|
|
||||||
(neo4j/defquery remove-assignments
|
|
||||||
"MATCH (s:schema)-[c:permission]-(:user)
|
|
||||||
WHERE s.uuid = $uuid
|
|
||||||
AND c.type = $permtype
|
|
||||||
DELETE c")
|
|
||||||
(neo4j/defquery create-assignments
|
|
||||||
"MATCH (s:schema), (u:user)
|
|
||||||
WHERE s.uuid = $uuid
|
|
||||||
AND u.uuid IN $users
|
|
||||||
CREATE (s)<-[:permission{type: $permtype}]-(u)")
|
|
||||||
(defn assign-users! [uuid users permission]
|
|
||||||
(neo4j/exec-queries!
|
|
||||||
[remove-assignments
|
|
||||||
{:uuid uuid
|
|
||||||
:permtype permission}]
|
|
||||||
[create-assignments
|
|
||||||
{:uuid uuid
|
|
||||||
:users users
|
|
||||||
:permtype permission}]))
|
|
||||||
|
|
||||||
(neo4j/defquery remove-schema-assignments
|
|
||||||
"MATCH (s1:schema)-[p:permission]-(s2:schema)
|
|
||||||
WHERE s1.uuid = $uuid
|
|
||||||
DELETE p")
|
|
||||||
(neo4j/defquery create-schema-assignments
|
|
||||||
"MATCH (s1:schema), (s2:schema)
|
|
||||||
WHERE s1.uuid = $uuid
|
|
||||||
AND s2.uuid IN $schemas
|
|
||||||
CREATE (s1)-[:permission]->(s2)")
|
|
||||||
(defn assign-schemas! [uuid schemas]
|
|
||||||
(neo4j/exec-queries!
|
|
||||||
[remove-schema-assignments
|
|
||||||
{:uuid uuid}]
|
|
||||||
[create-schema-assignments
|
|
||||||
{:uuid uuid :schemas schemas}]))
|
|
||||||
|
|
||||||
(neo4j/defquery find-by-instance
|
|
||||||
"MATCH (i:instance {uuid: $uuid})-[:of]->(s:schema)
|
|
||||||
RETURN s")
|
|
||||||
(defn find-by-instance! [uuid]
|
|
||||||
(-> find-by-instance
|
|
||||||
(neo4j/exec-query! {:uuid uuid})
|
|
||||||
first
|
|
||||||
:s))
|
|
@ -1,38 +1,41 @@
|
|||||||
(ns wanijo.schema.middleware
|
(ns wanijo.schema.middleware
|
||||||
(:require [ring.util.response :as resp]
|
(:require [ring.util.response :as resp]
|
||||||
[wanijo.infra.routing :refer [path]]
|
[wanijo.framework.routing :refer [path]]
|
||||||
[wanijo.schema.db :as db]))
|
[wanijo.schema.domain :as domain]))
|
||||||
|
|
||||||
(defn wrap-user-schemas! [handler]
|
(defn wrap-user-schemas [handler]
|
||||||
(fn [req]
|
(fn [req]
|
||||||
(if-let [uuid (get-in req [:session :uuid])]
|
(if-let [uuid (get-in req [:session :uuid])]
|
||||||
(handler (assoc-in req
|
(handler (assoc-in req
|
||||||
[:session :schemas]
|
[:session :schemas]
|
||||||
(db/all-readable-by! uuid)))
|
(domain/accessible-schemas! uuid)))
|
||||||
(handler req))))
|
(handler req))))
|
||||||
|
|
||||||
(defn write-permission-middleware! [schema-fn]
|
(defn write-permission-middleware [schema-fn]
|
||||||
(fn [handler]
|
(fn [handler]
|
||||||
(fn [req]
|
(fn [req]
|
||||||
(let [uuid (schema-fn req)]
|
(let [uuid (schema-fn req)
|
||||||
(if (db/has-user-write-permissions? uuid (-> req :session :uuid))
|
check-fn domain/has-user-write-permissions?]
|
||||||
|
(if (check-fn uuid (get-in req [:session :uuid]))
|
||||||
(handler req)
|
(handler req)
|
||||||
(assoc
|
(assoc
|
||||||
(resp/redirect (path :schema-show {:uuid uuid}))
|
(resp/redirect (path :schema-show {:uuid uuid}))
|
||||||
:flash ["No write permission for schema"]))))))
|
:flash ["No write permission for schema"]))))))
|
||||||
|
|
||||||
(defn wrap-allowed-to-write!
|
(defn wrap-allowed-to-write []
|
||||||
([schema-fn]
|
(write-permission-middleware #(get-in % [:params :uuid])))
|
||||||
(write-permission-middleware! schema-fn))
|
|
||||||
([]
|
|
||||||
(write-permission-middleware! #(get-in % [:params :uuid]))))
|
|
||||||
|
|
||||||
(defn wrap-allowed-to-read!
|
(defn wrap-allowed-to-read
|
||||||
[schema-fn]
|
([schema-fn]
|
||||||
(fn [handler]
|
(wrap-allowed-to-read schema-fn
|
||||||
(fn [req]
|
(fn [_]
|
||||||
(let [uuid (schema-fn req)]
|
(assoc (resp/redirect (path :schema-overview))
|
||||||
(if (db/has-user-read-permissions? uuid (-> req :session :uuid))
|
:flash ["No read permission for schema"]))))
|
||||||
(handler req)
|
([schema-fn not-allowed-fn]
|
||||||
(assoc (resp/redirect (path :home))
|
(fn [handler]
|
||||||
:flash ["No read permission for schema"]))))))
|
(fn [req]
|
||||||
|
(let [uuid (schema-fn req)
|
||||||
|
check-fn domain/has-user-read-permissions?]
|
||||||
|
(if (check-fn uuid (get-in req [:session :uuid]))
|
||||||
|
(handler req)
|
||||||
|
(not-allowed-fn req)))))))
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
(ns wanijo.user.db
|
|
||||||
(:require [clojure.spec.alpha :as spec]
|
|
||||||
[wanijo.infra.neo4j :as neo4j]))
|
|
||||||
|
|
||||||
(spec/def ::ident
|
|
||||||
(spec/and string? not-empty))
|
|
||||||
(spec/def ::name
|
|
||||||
(spec/or :empty #(or (empty? %) (nil? %))
|
|
||||||
:given (spec/and string? some?)))
|
|
||||||
(spec/def ::password
|
|
||||||
(spec/and string? #(> 7 (count %))))
|
|
||||||
|
|
||||||
(neo4j/defquery
|
|
||||||
find-user
|
|
||||||
"MATCH (n:user)
|
|
||||||
WHERE n.ident = $ident
|
|
||||||
RETURN n")
|
|
||||||
|
|
||||||
(defn find! [ident]
|
|
||||||
(->>
|
|
||||||
(neo4j/exec-query!
|
|
||||||
find-user
|
|
||||||
{:ident ident})
|
|
||||||
first
|
|
||||||
:n))
|
|
||||||
|
|
||||||
(comment
|
|
||||||
(macroexpand '(db/defquery test-find-user
|
|
||||||
"MATCH (u:user) WHERE u.ident = $ident RETURN u"))
|
|
||||||
(macroexpand '(neo4j/defquery
|
|
||||||
find-user
|
|
||||||
"MATCH (n:user) WHERE n.ident = $ident RETURN n"))
|
|
||||||
|
|
||||||
(require '[neo4j-clj.core :as db])
|
|
||||||
(db/defquery test-find-user
|
|
||||||
"MATCH (u:user) WHERE u.ident = $ident RETURN u")
|
|
||||||
(with-open [s (db/get-session @neo4j/conn)]
|
|
||||||
(test-find-user s {:ident "admin"}))
|
|
||||||
(neo4j/exec-query! test-find-user {:ident "admin"}))
|
|
||||||
|
|
||||||
(neo4j/defquery
|
|
||||||
all
|
|
||||||
"MATCH (u:user)
|
|
||||||
RETURN u
|
|
||||||
ORDER BY u.ident")
|
|
||||||
|
|
||||||
(defn all! []
|
|
||||||
(map :u
|
|
||||||
(neo4j/exec-query!
|
|
||||||
all
|
|
||||||
{})))
|
|
@ -0,0 +1,37 @@
|
|||||||
|
(ns wanijo.user.domain
|
||||||
|
(:require [clojure.spec.alpha :as spec]
|
||||||
|
[wanijo.framework.neo4j :as neo4j]))
|
||||||
|
|
||||||
|
(spec/def ::ident
|
||||||
|
(spec/and string? not-empty))
|
||||||
|
(spec/def ::name
|
||||||
|
(spec/or :empty #(or (empty? %) (nil? %))
|
||||||
|
:given (spec/and string? some?)))
|
||||||
|
(spec/def ::password
|
||||||
|
(spec/and string? #(> 7 (count %))))
|
||||||
|
|
||||||
|
(neo4j/defquery
|
||||||
|
find-user
|
||||||
|
"MATCH (n:user)
|
||||||
|
WHERE n.ident = {ident}
|
||||||
|
RETURN n")
|
||||||
|
|
||||||
|
(defn find! [ident]
|
||||||
|
(->>
|
||||||
|
(neo4j/exec-query!
|
||||||
|
find-user
|
||||||
|
{:ident ident})
|
||||||
|
first
|
||||||
|
:n))
|
||||||
|
|
||||||
|
(neo4j/defquery
|
||||||
|
all
|
||||||
|
"MATCH (u:user)
|
||||||
|
RETURN u
|
||||||
|
ORDER BY u.ident")
|
||||||
|
|
||||||
|
(defn all! []
|
||||||
|
(map :u
|
||||||
|
(neo4j/exec-query!
|
||||||
|
all
|
||||||
|
{})))
|
@ -1,51 +0,0 @@
|
|||||||
(ns wanijo.visualisation.db
|
|
||||||
(:require [clojure.spec.alpha :as spec]
|
|
||||||
[wanijo.infra.neo4j :as neo4j]
|
|
||||||
[wanijo.instance.db :as db-instance]
|
|
||||||
[wanijo.instance.domain :as domain-instance]))
|
|
||||||
|
|
||||||
(spec/def ::link-name
|
|
||||||
(spec/or :not-give nil?
|
|
||||||
:given string?))
|
|
||||||
(spec/def ::links-out
|
|
||||||
(spec/coll-of
|
|
||||||
(spec/merge ::domain-instance/instance
|
|
||||||
(spec/keys :req-un [::link-name]))))
|
|
||||||
(spec/def ::with-enriched-out-links
|
|
||||||
(spec/merge ::domain-instance/instance
|
|
||||||
(spec/keys :req-un [::links-out])))
|
|
||||||
|
|
||||||
(neo4j/defquery all-instance-connections
|
|
||||||
"MATCH
|
|
||||||
(source:instance)-[:of]->(schema:schema)
|
|
||||||
OPTIONAL MATCH
|
|
||||||
(source)-[link:link]->(target:instance),
|
|
||||||
(target)-[:of]->(target_schema:schema)
|
|
||||||
RETURN source, schema, link, target, target_schema")
|
|
||||||
(defn all-instance-connections! []
|
|
||||||
(neo4j/exec-query! all-instance-connections {}))
|
|
||||||
|
|
||||||
(neo4j/defquery search
|
|
||||||
"MATCH (i:instance)
|
|
||||||
WHERE i.name =~ $term
|
|
||||||
RETURN i
|
|
||||||
LIMIT 10")
|
|
||||||
(defn enrich-links [instance]
|
|
||||||
(update instance
|
|
||||||
:links-out
|
|
||||||
(fn [links-in]
|
|
||||||
(map #(assoc
|
|
||||||
(db-instance/full-instance-by-uuid!
|
|
||||||
(-> % :target :uuid))
|
|
||||||
:link-name
|
|
||||||
(-> % :label :name))
|
|
||||||
links-in))))
|
|
||||||
(defn search! [term]
|
|
||||||
{:post [(spec/assert (spec/coll-of ::with-enriched-out-links) %)]}
|
|
||||||
(->> (neo4j/exec-query! search {:term (str ".*" term ".*")})
|
|
||||||
(map #(db-instance/full-instance-by-uuid! (-> % :i :uuid)))
|
|
||||||
(map enrich-links)))
|
|
||||||
|
|
||||||
(defn instance! [uuid]
|
|
||||||
{:post [(spec/assert ::with-enriched-out-links %)]}
|
|
||||||
(enrich-links (db-instance/full-instance-by-uuid! uuid)))
|
|
@ -0,0 +1,13 @@
|
|||||||
|
(ns wanijo.visualisation.domain
|
||||||
|
(:require [wanijo.framework.neo4j :as neo4j]))
|
||||||
|
|
||||||
|
(neo4j/defquery all-instance-connections
|
||||||
|
"MATCH
|
||||||
|
(source:instance)-[:of]->(schema:schema)
|
||||||
|
OPTIONAL MATCH
|
||||||
|
(source)<-[:link_from]-(link:link)-[:link_to]->(target:instance),
|
||||||
|
(target)-[:of]->(target_schema:schema)
|
||||||
|
RETURN source, schema, link, target, target_schema")
|
||||||
|
|
||||||
|
(defn all-instance-connections! []
|
||||||
|
(neo4j/exec-query! all-instance-connections {}))
|
@ -1,51 +1,34 @@
|
|||||||
(ns wanijo.visualisation.routes
|
(ns wanijo.visualisation.routes
|
||||||
(:require [compojure.core :refer [defroutes wrap-routes
|
(:require [compojure.core :refer [defroutes wrap-routes
|
||||||
GET POST DELETE]]
|
GET POST DELETE]]
|
||||||
[wanijo.infra
|
[ring.util.response :as resp]
|
||||||
[routing :refer [register! path]]
|
[wanijo.framework.routing :refer [register! path]]
|
||||||
[view :as view]]
|
[wanijo.framework.view :as view]
|
||||||
[wanijo.instance.db :as db-instance]
|
[wanijo.instance.domain :as domain-instance]
|
||||||
[wanijo.schema.db :as domain-schema]
|
[wanijo.schema.domain :as domain-schema]
|
||||||
[wanijo.visualisation
|
[wanijo.visualisation
|
||||||
[db :as vis-db]
|
[domain :as vis-domain]
|
||||||
[viz :as viz]
|
[viz :as viz]
|
||||||
[view :as vis-view]]))
|
[view :as vis-view]]))
|
||||||
|
|
||||||
(defn all-instances [req]
|
(defn all-instances [req]
|
||||||
(view/layout
|
(view/layout!
|
||||||
:request req
|
:request req
|
||||||
:content
|
:content
|
||||||
[[:h1 "All Instances"]
|
[[:h1 "All Instances"]
|
||||||
(viz/all-instances (vis-db/all-instance-connections!))]))
|
(viz/all-instances (vis-domain/all-instance-connections!))]))
|
||||||
|
|
||||||
(defn all-schemas [req]
|
(defn all-schemas [req]
|
||||||
{:content-type "text/json"
|
{:content-type "text/json"
|
||||||
:body (domain-schema/accessible-schemas! (-> req :session :uuid))})
|
:body (domain-schema/accessible-schemas! (-> req :session :uuid))})
|
||||||
|
|
||||||
(defn instance [uuid]
|
|
||||||
{:content-type "text/json"
|
|
||||||
:body (vis-db/instance! uuid)})
|
|
||||||
|
|
||||||
(defn search [term]
|
|
||||||
{:content-type "text/json"
|
|
||||||
:body (map #(merge %
|
|
||||||
{:urls {:instance (path :vis-get-instance %)}})
|
|
||||||
(vis-db/search! term))})
|
|
||||||
|
|
||||||
(defroutes routes
|
(defroutes routes
|
||||||
(GET (register! :vis-explore "/vis/explore/:instance-uuid")
|
(GET (register! :vis-explore "/vis/explore/:instance-uuid")
|
||||||
[instance-uuid :as req]
|
[:as req]
|
||||||
(vis-view/index (db-instance/find-by-uuid! instance-uuid)
|
(vis-view/index req))
|
||||||
req))
|
|
||||||
(GET (register! :vis-all-instances "/vis/all-instances")
|
(GET (register! :vis-all-instances "/vis/all-instances")
|
||||||
[:as req]
|
[:as req]
|
||||||
(all-instances req))
|
(all-instances req))
|
||||||
(GET (register! :vis-all-schemas "/api/vis/schemas")
|
(GET (register! :vis-all-schemas "/api/vis/schemas")
|
||||||
[:as req]
|
[:as req]
|
||||||
(all-schemas req))
|
(all-schemas req)))
|
||||||
(GET (register! :vis-get-instance "/api/vis/instance/:uuid")
|
|
||||||
[uuid]
|
|
||||||
(instance uuid))
|
|
||||||
(GET (register! :vis-search-instance "/api/vis/search/:term")
|
|
||||||
[term]
|
|
||||||
(search term)))
|
|
||||||
|
@ -1,23 +1,14 @@
|
|||||||
(ns wanijo.visualisation.view
|
(ns wanijo.visualisation.view
|
||||||
(:require [hiccup.page :refer [include-js include-css]]
|
(:require [hiccup.page :refer [include-js]]
|
||||||
[hiccup.form :as hform]
|
[wanijo.framework.view :as view]))
|
||||||
[hiccup.core :refer [h]]
|
|
||||||
[wanijo.infra.routing :refer [path]]
|
|
||||||
[wanijo.infra.view :as view]))
|
|
||||||
|
|
||||||
(defn index [instance req]
|
(defn index [req]
|
||||||
(view/layout
|
(view/layout!
|
||||||
:request req
|
:request req
|
||||||
:head (list (include-css "/css/vis-network.min.css")
|
:head (include-js "/js/frontend.js")
|
||||||
(include-js "/js/vis-network.min.js"
|
:bottom [:script
|
||||||
"/js/vis.js"))
|
"Elm.Main.init({node: document.getElementById('visualisation')})"]
|
||||||
:content
|
:content
|
||||||
[[:h1 "Explore instance " [:small (h (:name instance))]]
|
[[:h1 "Visualisation"]
|
||||||
[:form.search {:action (path :vis-search-instance {:term ""})}
|
[:div#visualisation]
|
||||||
(hform/label "term" "Search Instance")
|
]))
|
||||||
(hform/text-field {:autofocus true} "term")
|
|
||||||
[:input {:style "display: none" :type "submit"}]]
|
|
||||||
[:div.vis-canvas {:data-instance-url (path :vis-get-instance instance)}]
|
|
||||||
[:p.flash--warn
|
|
||||||
"Changes to the visualisation will not
|
|
||||||
(yet) mirror to the actual database"]]))
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
(ns wanijo.infra.routing-test
|
(ns wanijo.framework.routing-test
|
||||||
(:require [clojure.test :refer :all]
|
(:require [clojure.test :refer :all]
|
||||||
[wanijo.infra.routing :refer [parse-path]]))
|
[wanijo.framework.routing :refer [parse-path]]))
|
||||||
|
|
||||||
(deftest test-parse-path
|
(deftest test-parse-path
|
||||||
(testing "no params in path"
|
(testing "no params in path"
|
@ -1,189 +0,0 @@
|
|||||||
(ns wanijo.infra.system-test
|
|
||||||
(:require [clojure.test :refer [deftest testing is]]
|
|
||||||
[neo4j-clj.core :as drv]
|
|
||||||
[clojure.string :as string]
|
|
||||||
[wanijo.infra.neo4j :as neo4j]
|
|
||||||
[wanijo.infra.repl :as repl]
|
|
||||||
[wanijo.schema.routes :as schema-routes]
|
|
||||||
[wanijo.attribute.routes :as attr-routes]
|
|
||||||
[wanijo.instance.routes :as inst-routes]
|
|
||||||
[wanijo.instance.forms :as inst-forms]
|
|
||||||
[wanijo.instance.db :as inst-db]
|
|
||||||
[clojure.pprint :as pp]))
|
|
||||||
|
|
||||||
(defn single-result
|
|
||||||
([cypher]
|
|
||||||
(single-result cypher
|
|
||||||
#(val (first %))))
|
|
||||||
([cypher extractor]
|
|
||||||
(extractor
|
|
||||||
(first
|
|
||||||
(neo4j/exec-query!
|
|
||||||
(drv/create-query cypher) {})))))
|
|
||||||
|
|
||||||
(defn multi-results [cypher extractor]
|
|
||||||
(extractor
|
|
||||||
(neo4j/exec-query!
|
|
||||||
(drv/create-query cypher) {})))
|
|
||||||
|
|
||||||
(deftest allround-system-test
|
|
||||||
(repl/setup-in-memory!)
|
|
||||||
(def user
|
|
||||||
(single-result "MATCH (u:user) RETURN u"
|
|
||||||
:u))
|
|
||||||
|
|
||||||
(testing "create schema"
|
|
||||||
(schema-routes/new! {:params {:name "test-schema"}
|
|
||||||
:session {:uuid (:uuid user)}})
|
|
||||||
(def schema
|
|
||||||
(single-result "MATCH (s:schema) RETURN s LIMIT 1" :s))
|
|
||||||
(is (= "test-schema" (:name schema)))
|
|
||||||
(is (not= nil (:created_at schema)))
|
|
||||||
(is (= (:uuid user)
|
|
||||||
(single-result "MATCH (s:schema)-[:created_by]->(u:user)
|
|
||||||
RETURN u.uuid")))
|
|
||||||
(is (= (:uuid user)
|
|
||||||
(single-result "MATCH (s:schema)
|
|
||||||
<-[:permission {type:'write'}]-(u:user)
|
|
||||||
RETURN u.uuid"))))
|
|
||||||
|
|
||||||
(testing "create attribute"
|
|
||||||
(attr-routes/new! {:params {:schema (:uuid schema)
|
|
||||||
:name "test-attr"
|
|
||||||
:type "string"
|
|
||||||
:required "1"}
|
|
||||||
:session {:uuid (:uuid user)}})
|
|
||||||
(def attr
|
|
||||||
(single-result "MATCH (a:attribute) RETURN a"))
|
|
||||||
(is (= "string" (:type attr)))
|
|
||||||
(is (= "test-attr" (:name attr)))
|
|
||||||
(is (= 1 (:required attr)))
|
|
||||||
(is (= (:uuid user)
|
|
||||||
(single-result "MATCH (a:attribute)-[:created_by]->(u:user)
|
|
||||||
RETURN u.uuid")))
|
|
||||||
(is (= (:uuid schema)
|
|
||||||
(single-result "MATCH (a:attribute)-[:of]->(s:schema)
|
|
||||||
RETURN s.uuid"))))
|
|
||||||
|
|
||||||
(testing "assign read"
|
|
||||||
(schema-routes/assign-users! {:params {:uuid (:uuid schema)
|
|
||||||
:assigned [(:uuid user)]
|
|
||||||
:permission "read"}})
|
|
||||||
(is (= (list ["read" (:uuid user)] ["write" (:uuid user)])
|
|
||||||
(multi-results "MATCH (s:schema)
|
|
||||||
<-[p:permission]-(u:user)
|
|
||||||
RETURN p.type AS type, u.uuid AS uuid"
|
|
||||||
#(map (juxt :type :uuid) %)))))
|
|
||||||
|
|
||||||
(testing "create instance"
|
|
||||||
(inst-routes/route-new!
|
|
||||||
{:params {:schema-uuid (:uuid schema)
|
|
||||||
:name "instance"
|
|
||||||
(inst-forms/attr->field-id attr) "attr-value"}
|
|
||||||
:session {:uuid (:uuid user)}})
|
|
||||||
(def instance
|
|
||||||
(single-result "MATCH (i:instance) RETURN i"))
|
|
||||||
(is (= "attr-value"
|
|
||||||
(single-result "MATCH (p:property) RETURN p.value")))
|
|
||||||
(is (= (:uuid user)
|
|
||||||
(single-result "MATCH (i:instance)-[:created_by]->(u:user)
|
|
||||||
RETURN u.uuid")))
|
|
||||||
(let [full-inst (inst-db/full-instance-by-uuid! (:uuid instance))]
|
|
||||||
(is (= "attr-value"
|
|
||||||
(-> full-inst :properties first :value)))
|
|
||||||
(is (= (:uuid attr)
|
|
||||||
(-> full-inst :properties first :attribute :uuid)))
|
|
||||||
(is (empty? (:tags full-inst)))
|
|
||||||
(is (empty? (:links-in full-inst)))
|
|
||||||
(is (empty? (:links-out full-inst)))))
|
|
||||||
|
|
||||||
(testing "create second instance and linking"
|
|
||||||
(inst-routes/route-new!
|
|
||||||
{:params {:schema-uuid (:uuid schema)
|
|
||||||
:name "instance2"
|
|
||||||
(inst-forms/attr->field-id attr) "attr-value2"}
|
|
||||||
:session {:uuid (:uuid user)}})
|
|
||||||
(def instance2
|
|
||||||
(single-result "MATCH (i:instance)
|
|
||||||
WITH MAX(i.created_at) AS max_created_at
|
|
||||||
MATCH (i:instance)
|
|
||||||
WHERE i.created_at = max_created_at
|
|
||||||
RETURN i"))
|
|
||||||
(is (= "instance2" (:name instance2)))
|
|
||||||
|
|
||||||
(inst-routes/route-create-link!
|
|
||||||
(:uuid instance)
|
|
||||||
(:uuid schema)
|
|
||||||
{:params {:name "link-name"
|
|
||||||
:instances [(:uuid instance2)]}
|
|
||||||
:session {:uuid (:uuid user)}})
|
|
||||||
(let [link (single-result "MATCH ()-[l:link]-() RETURN l")]
|
|
||||||
(is (= "link-name" (:name link)))
|
|
||||||
(is (= (:uuid user) (:created_by link)))
|
|
||||||
(is (some? (:created_at link))))
|
|
||||||
|
|
||||||
(is (= (:uuid instance)
|
|
||||||
(single-result "MATCH (i:instance)-[:link]->(:instance)
|
|
||||||
RETURN i.uuid")))
|
|
||||||
|
|
||||||
(is (= (:uuid instance2)
|
|
||||||
(single-result "MATCH (i:instance)<-[:link]-(:instance)
|
|
||||||
RETURN i.uuid"))))
|
|
||||||
|
|
||||||
(testing "show instances"
|
|
||||||
(let [resp (inst-routes/route-show!
|
|
||||||
(:uuid instance)
|
|
||||||
{:session {:uuid (:uuid user)}})]
|
|
||||||
(is (true? (string? resp)))
|
|
||||||
(is (true? (string/includes? resp (:name instance))))
|
|
||||||
(is (true? (string/includes? resp (:name schema)))))
|
|
||||||
(let [resp (inst-routes/route-show!
|
|
||||||
(:uuid instance2)
|
|
||||||
{:session {:uuid (:uuid user)}})]
|
|
||||||
(is (true? (string? resp)))
|
|
||||||
(is (true? (string/includes? resp (:name instance))))
|
|
||||||
(is (true? (string/includes? resp (:name schema))))))
|
|
||||||
|
|
||||||
(testing "modifying first instance"
|
|
||||||
(let [prop-uuid (single-result
|
|
||||||
(str
|
|
||||||
"MATCH (i:instance)<-[:of]-(p:property)
|
|
||||||
WHERE i.uuid = '" (:uuid instance) "'
|
|
||||||
RETURN p.uuid"))]
|
|
||||||
(inst-routes/route-edit!
|
|
||||||
(:uuid instance)
|
|
||||||
{:params {:name "new-instance-1"
|
|
||||||
(inst-forms/attr->field-id attr) "new-value"
|
|
||||||
(inst-forms/attr->uuid-field-id attr) prop-uuid}
|
|
||||||
:session {:uuid (:uuid user)}})
|
|
||||||
(is (= "new-value"
|
|
||||||
(single-result
|
|
||||||
(str
|
|
||||||
"MATCH (p:property)
|
|
||||||
WHERE p.uuid = '" prop-uuid "'
|
|
||||||
RETURN p.value"))))
|
|
||||||
(is (= "new-value"
|
|
||||||
(single-result
|
|
||||||
(str
|
|
||||||
"MATCH (rp:rev_property)
|
|
||||||
-[:of]->(rev:revision)
|
|
||||||
-[:of]->(i:instance)
|
|
||||||
WHERE i.uuid = '" (:uuid instance) "'
|
|
||||||
RETURN rp.value"))))
|
|
||||||
(is (= 1 (single-result "MATCH (r:revision) RETURN COUNT(r)")))))
|
|
||||||
|
|
||||||
(testing "delete first instance"
|
|
||||||
(inst-routes/route-delete! (:uuid instance))
|
|
||||||
(is (= 1 (single-result "MATCH (i:instance) RETURN COUNT(i)")))
|
|
||||||
(is (= 1 (single-result "MATCH (p:property) RETURN COUNT(p)")))
|
|
||||||
(is (= 1 (single-result "MATCH (s:schema) RETURN COUNT(s)")))
|
|
||||||
(is (= 0 (single-result "MATCH ()-[l:link]-() RETURN COUNT(l)"))))
|
|
||||||
|
|
||||||
(testing "delete second instance"
|
|
||||||
(inst-routes/route-delete! (:uuid instance2))
|
|
||||||
(is (= 0 (single-result "MATCH (i:instance) RETURN COUNT(i)")))
|
|
||||||
(is (= 0 (single-result "MATCH (p:property) RETURN COUNT(p)")))
|
|
||||||
(is (= 1 (single-result "MATCH (s:schema) RETURN COUNT(s)")))))
|
|
||||||
|
|
||||||
(comment
|
|
||||||
(allround-system-test))
|
|
@ -0,0 +1,13 @@
|
|||||||
|
(ns wanijo.instance.domain-test
|
||||||
|
(:require [clojure.test :refer :all]
|
||||||
|
[leiningen.neo4j :refer [with-test-db]]
|
||||||
|
[neo4j-clj.core :as db]
|
||||||
|
[wanijo.instance.domain :as domain]))
|
||||||
|
|
||||||
|
(deftest instances-are-created
|
||||||
|
(with-test-db
|
||||||
|
"/tmp"
|
||||||
|
(fn []
|
||||||
|
(binding [wanijo.framework.neo4j/*conn*
|
||||||
|
(atom (db/connect "bolt://localhost"))]
|
||||||
|
(println "jadda")))))
|