Project files
232
LICENSE
Normal file
@ -0,0 +1,232 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright © 2007 Free Software Foundation, Inc. <http://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 <http://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 <http://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 <http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||||
23
reactFrontend/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
36
reactFrontend/README.md
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
## Project Overview
|
||||||
|
|
||||||
|
This project is a web application built using JavaScript, npm, yarn, and React. It is designed to provide users with an interface to view and manage purchases, articles, and analyses.
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
The project is structured as follows:
|
||||||
|
|
||||||
|
- `App.js`: This is the main entry point of the application. It imports and renders the necessary components and sets up the routing.
|
||||||
|
|
||||||
|
- `components/`: This directory contains all the components used in the application. Each component is a separate file and is responsible for rendering a specific part of the UI.
|
||||||
|
|
||||||
|
- `App.css`: This file contains the styles used in the application.
|
||||||
|
|
||||||
|
- `MyRoutes.js`: This file contains the routing configuration for the application.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
The project uses the following dependencies:
|
||||||
|
|
||||||
|
- `react`: A JavaScript library for building user interfaces.
|
||||||
|
|
||||||
|
- `react-router-dom`: A library for routing in React applications.
|
||||||
|
|
||||||
|
- `@mui/material`: A library of React components that implement Google's Material Design.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
To get started with the project, follow these steps:
|
||||||
|
|
||||||
|
1. Clone the repository to your local machine.
|
||||||
|
|
||||||
|
2. Install the necessary dependencies using `npm` or `yarn`.
|
||||||
|
|
||||||
|
3. Run the application using `npm start` or `yarn start`.
|
||||||
|
|
||||||
57
reactFrontend/package.json
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@devexpress/dx-react-core": "^3.0.2",
|
||||||
|
"@devexpress/dx-react-grid": "^3.0.2",
|
||||||
|
"@devexpress/dx-react-grid-material-ui": "^3.0.2",
|
||||||
|
"@emotion/react": "^11.11.1",
|
||||||
|
"@emotion/styled": "^11.11.0",
|
||||||
|
"@mui/icons-material": "^5.14.3",
|
||||||
|
"@mui/lab": "^5.0.0-alpha.139",
|
||||||
|
"@mui/material": "^5.14.4",
|
||||||
|
"@mui/x-data-grid": "^6.11.1",
|
||||||
|
"@mui/x-date-pickers": "^6.11.1",
|
||||||
|
"@testing-library/jest-dom": "^5.17.0",
|
||||||
|
"@testing-library/react": "^14.0.0",
|
||||||
|
"@testing-library/user-event": "^14.4.3",
|
||||||
|
"axios": "^1.4.0",
|
||||||
|
"date-fns": "^2.30.0",
|
||||||
|
"dayjs": "^1.11.9",
|
||||||
|
"graphql": "^16.7.1",
|
||||||
|
"plotly.js": "^2.25.2",
|
||||||
|
"react": "^18.0.0",
|
||||||
|
"react-dom": "^18.0.0",
|
||||||
|
"react-dropzone": "^12.0.5",
|
||||||
|
"react-plotly.js": "^2.6.0",
|
||||||
|
"react-router-dom": "^6.3.0",
|
||||||
|
"react-scripts": "5.0.1",
|
||||||
|
"uuid": "^9.0.0",
|
||||||
|
"web-vitals": "^2.1.4"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "react-scripts start",
|
||||||
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": [
|
||||||
|
"react-app",
|
||||||
|
"react-app/jest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
54
reactFrontend/package.json.old
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@devexpress/dx-react-core": "^3.0.2",
|
||||||
|
"@devexpress/dx-react-grid": "^3.0.2",
|
||||||
|
"@devexpress/dx-react-grid-material-ui": "^3.0.2",
|
||||||
|
"@emotion/react": "^11.9.0",
|
||||||
|
"@emotion/styled": "^11.8.1",
|
||||||
|
"@mui/icons-material": "^5.6.1",
|
||||||
|
"@mui/lab": "^5.0.0-alpha.86",
|
||||||
|
"@mui/material": "^5.6.1",
|
||||||
|
"@mui/x-data-grid": "^5.9.0",
|
||||||
|
"@mui/x-date-pickers": "^6.11.1",
|
||||||
|
"@testing-library/jest-dom": "^5.16.4",
|
||||||
|
"@testing-library/react": "^13.0.1",
|
||||||
|
"@testing-library/user-event": "^13.5.0",
|
||||||
|
"axios": "^0.26.1",
|
||||||
|
"date-fns": "^2.28.0",
|
||||||
|
"graphql": "^16.3.0",
|
||||||
|
"react": "^18.0.0",
|
||||||
|
"react-dom": "^18.0.0",
|
||||||
|
"react-dropzone": "^12.0.5",
|
||||||
|
"react-router-dom": "^6.3.0",
|
||||||
|
"react-scripts": "5.0.1",
|
||||||
|
"uuid": "^9.0.0",
|
||||||
|
"web-vitals": "^2.1.4"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "react-scripts start",
|
||||||
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": [
|
||||||
|
"react-app",
|
||||||
|
"react-app/jest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
reactFrontend/public/favicon.ico
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
43
reactFrontend/public/index.html
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta name="theme-color" content="#000000" />
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content="Web site created using create-react-app"
|
||||||
|
/>
|
||||||
|
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||||
|
<!--
|
||||||
|
manifest.json provides metadata used when your web app is installed on a
|
||||||
|
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||||
|
-->
|
||||||
|
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||||
|
<!--
|
||||||
|
Notice the use of %PUBLIC_URL% in the tags above.
|
||||||
|
It will be replaced with the URL of the `public` folder during the build.
|
||||||
|
Only files inside the `public` folder can be referenced from the HTML.
|
||||||
|
|
||||||
|
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||||
|
work correctly both with client-side routing and a non-root public URL.
|
||||||
|
Learn how to configure a non-root public URL by running `npm run build`.
|
||||||
|
-->
|
||||||
|
<title>React App</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
<!--
|
||||||
|
This HTML file is a template.
|
||||||
|
If you open it directly in the browser, you will see an empty page.
|
||||||
|
|
||||||
|
You can add webfonts, meta tags, or analytics to this file.
|
||||||
|
The build step will place the bundled scripts into the <body> tag.
|
||||||
|
|
||||||
|
To begin the development, run `npm start` or `yarn start`.
|
||||||
|
To create a production bundle, use `npm run build` or `yarn build`.
|
||||||
|
-->
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
BIN
reactFrontend/public/logo192.png
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
reactFrontend/public/logo512.png
Normal file
|
After Width: | Height: | Size: 9.4 KiB |
25
reactFrontend/public/manifest.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"short_name": "React App",
|
||||||
|
"name": "Create React App Sample",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "favicon.ico",
|
||||||
|
"sizes": "64x64 32x32 24x24 16x16",
|
||||||
|
"type": "image/x-icon"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "logo192.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "192x192"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "logo512.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "512x512"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"start_url": ".",
|
||||||
|
"display": "standalone",
|
||||||
|
"theme_color": "#000000",
|
||||||
|
"background_color": "#ffffff"
|
||||||
|
}
|
||||||
3
reactFrontend/public/robots.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# https://www.robotstxt.org/robotstxt.html
|
||||||
|
User-agent: *
|
||||||
|
Disallow:
|
||||||
38
reactFrontend/src/App.css
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
.App {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-logo {
|
||||||
|
height: 40vmin;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: no-preference) {
|
||||||
|
.App-logo {
|
||||||
|
animation: App-logo-spin infinite 20s linear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-header {
|
||||||
|
background-color: #282c34;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: calc(10px + 2vmin);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-link {
|
||||||
|
color: #61dafb;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes App-logo-spin {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
54
reactFrontend/src/App.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import './App.css';
|
||||||
|
|
||||||
|
import { BrowserRouter, Routes, Route } from "react-router-dom";
|
||||||
|
|
||||||
|
import {Box, Stack} from '@mui/material';
|
||||||
|
|
||||||
|
import Navbar from "./components/Navbar";
|
||||||
|
import Sidebar from "./components/Sidebar";
|
||||||
|
//import Feed from "./components/Feed";
|
||||||
|
|
||||||
|
import PurchaseDetails from "./components/PurchaseDetails.component";
|
||||||
|
import ArticleDetails from "./components/ArticleDetails.component";
|
||||||
|
import ArticleOverview from "./components/ArticleOverview.component";
|
||||||
|
import PurchaseOverview from "./components/PurchaseOverview.component";
|
||||||
|
import AnalysesOverview from "./components/AnalysesOverview.component";
|
||||||
|
|
||||||
|
//import MyRoutes from './MyRoutes';
|
||||||
|
|
||||||
|
const App = () => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
{/* Set up the browser router */}
|
||||||
|
<BrowserRouter>
|
||||||
|
{/* Render the navbar */}
|
||||||
|
<Navbar />
|
||||||
|
{/* Set up a stack layout with a sidebar and content */}
|
||||||
|
<Stack direction="row" spacing={2} justifyContent="space-between">
|
||||||
|
{/* Render the sidebar */}
|
||||||
|
<Sidebar />
|
||||||
|
{/* Set up the routes */}
|
||||||
|
<Routes>
|
||||||
|
{/* Set up the route for the purchase overview */}
|
||||||
|
<Route path="/" element={<PurchaseOverview />} exact/>
|
||||||
|
{/* Set up the route for the purchase details */}
|
||||||
|
<Route path="/PurchaseDetails" element={<PurchaseDetails />} />
|
||||||
|
{/* Set up the route for the article details */}
|
||||||
|
<Route path="/ArticleDetails" element={<ArticleDetails />} />
|
||||||
|
{/* Set up the route for the article overview */}
|
||||||
|
<Route path="/Articles" element={<ArticleOverview />} />
|
||||||
|
{/* Set up the route for the analyses overview */}
|
||||||
|
<Route path="/Analyses" element={<AnalysesOverview />} />
|
||||||
|
</Routes>
|
||||||
|
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
</BrowserRouter>
|
||||||
|
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
||||||
8
reactFrontend/src/App.test.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import App from './App';
|
||||||
|
|
||||||
|
test('renders learn react link', () => {
|
||||||
|
render(<App />);
|
||||||
|
const linkElement = screen.getByText(/learn react/i);
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
});
|
||||||
23
reactFrontend/src/MyRoutes.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { BrowserRouter, Routes, Route } from "react-router-dom";
|
||||||
|
|
||||||
|
import PurchaseDetails from "./components/PurchaseDetails.component";
|
||||||
|
import ArticleDetails from "./components/ArticleDetails.component";
|
||||||
|
import ArticleOverview from "./components/ArticleOverview.component";
|
||||||
|
import Feed from "./components/Feed";
|
||||||
|
|
||||||
|
const MyRoutes = (props) => {
|
||||||
|
return (
|
||||||
|
<BrowserRouter>
|
||||||
|
<Routes>
|
||||||
|
<Route path="/" element={<Feed />} exact/>
|
||||||
|
<Route path="/PurchaseDetails" element={<PurchaseDetails />} />
|
||||||
|
<Route path="/ArticleDetails" element={<ArticleDetails />} />
|
||||||
|
<Route path="/Articles" element={<ArticleOverview />} />
|
||||||
|
</Routes>
|
||||||
|
</BrowserRouter>
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MyRoutes
|
||||||
221
reactFrontend/src/components/AnalysesOverview.component.jsx
Normal file
@ -0,0 +1,221 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
|
|
||||||
|
//import Button from '@mui/material/Button';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
import Container from '@mui/material/Container';
|
||||||
|
import Grid from '@mui/material/Grid';
|
||||||
|
import { Button, Paper, styled, } from '@mui/material'
|
||||||
|
import Tabs from '@mui/material/Tabs';
|
||||||
|
import Tab from '@mui/material/Tab';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import Box from '@mui/material/Box';
|
||||||
|
|
||||||
|
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
|
||||||
|
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
||||||
|
import { DatePicker } from '@mui/x-date-pickers/DatePicker';
|
||||||
|
|
||||||
|
import Plot from 'react-plotly.js';
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
function TabPanel(props) {
|
||||||
|
const { children, value, index, ...other } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
role="tabpanel"
|
||||||
|
hidden={value !== index}
|
||||||
|
id={`vertical-tabpanel-${index}`}
|
||||||
|
aria-labelledby={`vertical-tab-${index}`}
|
||||||
|
{...other}
|
||||||
|
>
|
||||||
|
{value === index && (
|
||||||
|
<Box sx={{ p: 3 }}>
|
||||||
|
<Typography>{children}</Typography>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TabPanel.propTypes = {
|
||||||
|
children: PropTypes.node,
|
||||||
|
index: PropTypes.number.isRequired,
|
||||||
|
value: PropTypes.number.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function a11yProps(index) {
|
||||||
|
return {
|
||||||
|
id: `vertical-tab-${index}`,
|
||||||
|
'aria-controls': `vertical-tabpanel-${index}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const AnalysesOverview = (props) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [tableData, setTableData] = useState([{article_id: -1, count: 0}]);
|
||||||
|
const [fromDate, setFromDate] = useState(dayjs('2023-01-01'));
|
||||||
|
const [toDate, setToDate] = useState(dayjs('2023-09-01'));
|
||||||
|
const [value, setValue] = React.useState(0);
|
||||||
|
|
||||||
|
const handleChange = (event, newValue) => {
|
||||||
|
setValue(newValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
|
||||||
|
},[])
|
||||||
|
|
||||||
|
const handlePlotButton = async () => {
|
||||||
|
const data = {fromDate: fromDate.format("YYYY-MM-DD"), toDate: toDate.format("YYYY-MM-DD")};
|
||||||
|
console.log(data);
|
||||||
|
const receivedData = await axios.post(baseURL+"/analyses/countArticles", {
|
||||||
|
data: data,
|
||||||
|
})
|
||||||
|
setTableData(receivedData.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleBrandPlotButton = async () => {
|
||||||
|
const data = {fromDate: fromDate.format("YYYY-MM-DD"), toDate: toDate.format("YYYY-MM-DD")};
|
||||||
|
console.log(data);
|
||||||
|
const receivedData = await axios.post(baseURL+"/analyses/countBrands", {
|
||||||
|
data: data,
|
||||||
|
})
|
||||||
|
setTableData(receivedData.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ height: 800, width: '100%' }}>
|
||||||
|
|
||||||
|
<Typography variant="h2" gutterBottom>
|
||||||
|
Übersicht über alle Analysen
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Box
|
||||||
|
sx={{ flexGrow: 1, bgcolor: 'background.paper', display: 'flex', height: 500 }} >
|
||||||
|
<Tabs
|
||||||
|
orientation="vertical"
|
||||||
|
variant="scrollable"
|
||||||
|
value={value}
|
||||||
|
onChange={handleChange}
|
||||||
|
aria-label="Vertical tabs example"
|
||||||
|
sx={{ borderRight: 1, borderColor: 'divider' }}
|
||||||
|
>
|
||||||
|
<Tab label="Barplot: Häufigkeit Artikel" {...a11yProps(0)} />
|
||||||
|
<Tab label="Barplot: Häufigkeit Marke" {...a11yProps(1)} />
|
||||||
|
<Tab label="Item Three" {...a11yProps(2)} />
|
||||||
|
<Tab label="Item Four" {...a11yProps(3)} />
|
||||||
|
<Tab label="Item Five" {...a11yProps(4)} />
|
||||||
|
<Tab label="Item Six" {...a11yProps(5)} />
|
||||||
|
<Tab label="Item Seven" {...a11yProps(6)} />
|
||||||
|
</Tabs>
|
||||||
|
<TabPanel value={value} index={0}>
|
||||||
|
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
||||||
|
<DatePicker
|
||||||
|
label="Start Datum"
|
||||||
|
format="DD.MM.YYYY"
|
||||||
|
value={dayjs(fromDate)}
|
||||||
|
onChange={val => {setFromDate(val)}}
|
||||||
|
/>
|
||||||
|
<DatePicker
|
||||||
|
label="End Datum"
|
||||||
|
format="DD.MM.YYYY"
|
||||||
|
value={dayjs(toDate)}
|
||||||
|
onChange={val => {setToDate(val)}}
|
||||||
|
/>
|
||||||
|
<Button variant="contained"
|
||||||
|
onClick={handlePlotButton}
|
||||||
|
>
|
||||||
|
Plotten
|
||||||
|
</Button>
|
||||||
|
</LocalizationProvider>
|
||||||
|
<Plot
|
||||||
|
data={[
|
||||||
|
{
|
||||||
|
type: 'bar',
|
||||||
|
y: Array.from(Array(tableData.length).keys()),
|
||||||
|
x: tableData.map( (val) => (val.count) ),
|
||||||
|
orientation: 'h'
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
layout={ {height: 3500, title: 'Häufigkeit Artikel',
|
||||||
|
yaxis: {
|
||||||
|
tickvals: Array.from(Array(tableData.length).keys()),
|
||||||
|
ticktext: tableData.map( (val) => (val.article_name) ),
|
||||||
|
automargin: true,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</TabPanel>
|
||||||
|
<TabPanel value={value} index={1}>
|
||||||
|
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
||||||
|
<DatePicker
|
||||||
|
label="Start Datum"
|
||||||
|
format="DD.MM.YYYY"
|
||||||
|
value={dayjs(fromDate)}
|
||||||
|
onChange={val => {setFromDate(val)}}
|
||||||
|
/>
|
||||||
|
<DatePicker
|
||||||
|
label="End Datum"
|
||||||
|
format="DD.MM.YYYY"
|
||||||
|
value={dayjs(toDate)}
|
||||||
|
onChange={val => {setToDate(val)}}
|
||||||
|
/>
|
||||||
|
<Button variant="contained"
|
||||||
|
onClick={handleBrandPlotButton}
|
||||||
|
>
|
||||||
|
Plotten
|
||||||
|
</Button>
|
||||||
|
</LocalizationProvider>
|
||||||
|
<Plot
|
||||||
|
data={[
|
||||||
|
{
|
||||||
|
type: 'bar',
|
||||||
|
y: Array.from(Array(tableData.length).keys()),
|
||||||
|
x: tableData.map( (val) => (val.count) ),
|
||||||
|
orientation: 'h'
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
layout={ {height: 3500, title: 'Häufigkeit Marken',
|
||||||
|
yaxis: {
|
||||||
|
tickvals: Array.from(Array(tableData.length).keys()),
|
||||||
|
ticktext: tableData.map( (val) => (val.brand_name) ),
|
||||||
|
automargin: true,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</TabPanel>
|
||||||
|
<TabPanel value={value} index={2}>
|
||||||
|
Item Three
|
||||||
|
</TabPanel>
|
||||||
|
<TabPanel value={value} index={3}>
|
||||||
|
Item Four
|
||||||
|
</TabPanel>
|
||||||
|
<TabPanel value={value} index={4}>
|
||||||
|
Item Five
|
||||||
|
</TabPanel>
|
||||||
|
<TabPanel value={value} index={5}>
|
||||||
|
Item Six
|
||||||
|
</TabPanel>
|
||||||
|
<TabPanel value={value} index={6}>
|
||||||
|
Item Seven
|
||||||
|
</TabPanel>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AnalysesOverview
|
||||||
535
reactFrontend/src/components/ArticleDetails.component.js
Normal file
@ -0,0 +1,535 @@
|
|||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import { useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { Grid, Typography, TextField, Select, MenuItem, Stack} from '@mui/material'
|
||||||
|
import { Button, Paper, styled, } from '@mui/material'
|
||||||
|
import Box from '@mui/material/Box';
|
||||||
|
import { grey } from '@mui/material/colors';
|
||||||
|
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
|
|
||||||
|
//import ReceipeCanvas from "./Canvas.component"
|
||||||
|
import CategoryTree from "./CategoryTree.component"
|
||||||
|
import ListFieldApi from "./ListFieldApi.component"
|
||||||
|
import PackagingDataGrid2 from "./PackagingDataGrid2.component"
|
||||||
|
import NutriDataGrid from "./NutriDataGrid.component"
|
||||||
|
import PictureCard from "./pictureCard.component"
|
||||||
|
import IngredienceDataGrid from "./IngredienceDataGrid.component"
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
const Item = styled(Paper)(({ theme }) => ({
|
||||||
|
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
|
||||||
|
...theme.typography.body2,
|
||||||
|
padding: theme.spacing(1),
|
||||||
|
textAlign: 'center',
|
||||||
|
color: theme.palette.text.secondary,
|
||||||
|
}));
|
||||||
|
|
||||||
|
//article is pushed from PurchaseDetail.component
|
||||||
|
const ArticleDetails = (props) => {
|
||||||
|
const location = useLocation();
|
||||||
|
var earlyExit = false;
|
||||||
|
if (location.state != null){
|
||||||
|
console.log(location)
|
||||||
|
console.log(location.state.id)
|
||||||
|
console.log(location.state.article_id)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("No data to show");
|
||||||
|
console.log(location)
|
||||||
|
location.state = {'article_id': {'name': '','EAN':'', 'brand':''}};
|
||||||
|
console.log(location)
|
||||||
|
earlyExit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const units = ['kg','g','l','ml','St.','kJ','kcal','µg'];
|
||||||
|
const grades = ['','A','B','C','D','E'];
|
||||||
|
const novas = ['','1','2','3','4'];
|
||||||
|
|
||||||
|
const [article, setArticle] = useState(location.state.article_id);
|
||||||
|
const [name, setName] = useState(article.name);
|
||||||
|
const [EAN, setEAN] = useState(article.EAN);
|
||||||
|
const [offlink, setOfflink] = useState(article.offlink);
|
||||||
|
const [quantityPerPackage, setQuantityPerPackage] = useState(article.quantityPerPackage);
|
||||||
|
const [unit, setUnit] = useState(article.unit);
|
||||||
|
//const [nutritionGrade, setNutritionGrade] = useState(article.nutritionGrade);
|
||||||
|
//const [novaGroup, setNovaGroup] = useState(article.novaGroup);
|
||||||
|
//const [ecoGrade, setEcoGrade] = useState(article.ecoGrade);
|
||||||
|
|
||||||
|
const [snackbar, setSnackbar] = useState(null);
|
||||||
|
|
||||||
|
const EANvalid = () => {
|
||||||
|
if (EAN === null)
|
||||||
|
return false;
|
||||||
|
else {
|
||||||
|
if (EAN.length === 13 || EAN.length === 8) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSearchButton = async () => {
|
||||||
|
try {
|
||||||
|
const ans = await axios.get(baseURL+"/offsearch_get_by_ean/"+EAN+"/"+article.pk, { });
|
||||||
|
|
||||||
|
//setArticle(ans.data.article);
|
||||||
|
const newArticle = ans.data;
|
||||||
|
setArticle(newArticle);
|
||||||
|
|
||||||
|
//console.log('New Article:')
|
||||||
|
//console.log(newArticle)
|
||||||
|
location.state.article_id = newArticle;
|
||||||
|
setSnackbar({ children: 'Daten erfolgreich übernommen', severity: 'success' });
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(error){
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handelArticleChange = (value) => {
|
||||||
|
setArticle(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleArticleChangeAPI = async (event, field, value) => {
|
||||||
|
try {
|
||||||
|
if (field === 'nutritionGrade' || field === 'novaGroup' || field === 'ecoGrade'){
|
||||||
|
console.log(value)
|
||||||
|
const newArticle = { ...article, [field]: value};
|
||||||
|
const sendArticle = await axios.put(baseURL+"/article/"+article.pk, {
|
||||||
|
article: newArticle
|
||||||
|
});
|
||||||
|
setArticle(newArticle);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
const newArticle = { ...article, [field]: value};
|
||||||
|
const sendArticle = await axios.put(baseURL+"/article/"+article.pk, {
|
||||||
|
article: newArticle
|
||||||
|
});
|
||||||
|
setArticle(newArticle);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(error){
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
setName(eval('article.'+field));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const handleCloseSnackbar = () => setSnackbar(null);
|
||||||
|
|
||||||
|
if (earlyExit){
|
||||||
|
return(<div> </div>);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<Typography variant="h3" component="div" gutterBottom>
|
||||||
|
{article.brand === null ? '': article.brand.name} {" "+ article.name}
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="nameField"
|
||||||
|
//defaultValue={name != null ? name : ""}
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
error={(article.name.length === 0)}
|
||||||
|
label="Name"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
onBlur={(e) => handleArticleChangeAPI(e,'name', e.target.value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<TextField
|
||||||
|
//autoFocus
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="EAN"
|
||||||
|
value={EAN != null ? EAN : "" }
|
||||||
|
onChange={(e) => setEAN(e.target.value)}
|
||||||
|
error={!EANvalid()}
|
||||||
|
label="EAN/EAN-13"
|
||||||
|
type="number"
|
||||||
|
variant="standard"
|
||||||
|
onBlur={(e) => handleArticleChangeAPI(e,'EAN', e.target.value)}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<TextField
|
||||||
|
//autoFocus
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="offlink"
|
||||||
|
value={offlink != null ? offlink : ""}
|
||||||
|
onChange={(e) => setOfflink(e.target.value)}
|
||||||
|
label="OpenFoodFact Link"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
onBlur={(e) => handleArticleChangeAPI(e,'offlink', e.target.value)}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={4}>
|
||||||
|
<Button variant="contained"
|
||||||
|
onClick={handleSearchButton}
|
||||||
|
disabled={!EANvalid()}
|
||||||
|
>
|
||||||
|
EAN bei OpenFoodFact suchen
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
{/*-----------------------------------------------------------------------------------*/}
|
||||||
|
{/*-----------------------------------------------------------------------------------*/}
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<Typography variant="h4" component="div" gutterBottom textAlign="center">
|
||||||
|
Produkteigenschaften
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={4}>
|
||||||
|
<PictureCard
|
||||||
|
type="Artikelbild"
|
||||||
|
article={article}
|
||||||
|
pictureType="frontImage"
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
>
|
||||||
|
</PictureCard>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={8}>
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<ListFieldApi
|
||||||
|
apiURL="/article/brands/"
|
||||||
|
titleName="Marke"
|
||||||
|
addName="Marke"
|
||||||
|
multiple={false}
|
||||||
|
value={article.brand}
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
article={article}
|
||||||
|
fieldName={'brand'}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={10}>
|
||||||
|
<TextField
|
||||||
|
//autoFocus
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="quantityPerPackage"
|
||||||
|
value={quantityPerPackage != null ? quantityPerPackage : ""}
|
||||||
|
onChange={(e) => setQuantityPerPackage(e.target.value)}
|
||||||
|
label="Mengenangabe"
|
||||||
|
type="number"
|
||||||
|
variant="standard"
|
||||||
|
onBlur={(e) => handleArticleChangeAPI(e,'quantityPerPackage',e.target.value)}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={2}>
|
||||||
|
<Select
|
||||||
|
fullWidth
|
||||||
|
id="unit"
|
||||||
|
value={unit}
|
||||||
|
label="Einheit"
|
||||||
|
onChange={(e) => {setUnit(e.target.value);handleArticleChangeAPI(e,'unit',e.target.value)}}
|
||||||
|
>
|
||||||
|
{units.map((unit) => (
|
||||||
|
<MenuItem
|
||||||
|
key={unit}
|
||||||
|
value={unit}
|
||||||
|
//style={getStyles(name, personName, theme)}
|
||||||
|
>
|
||||||
|
{unit}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<Typography variant="subtitle1" component="div" gutterBottom>
|
||||||
|
Verpackung
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<PackagingDataGrid2
|
||||||
|
articleId={article.pk}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<ListFieldApi
|
||||||
|
apiURL="/article/labels/"
|
||||||
|
titleName="Kennzeichnungen"
|
||||||
|
addName="Label"
|
||||||
|
multiple={true}
|
||||||
|
value={article.labels}
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
article={article}
|
||||||
|
fieldName={'labels'}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<Typography variant="subtitle1" component="div" gutterBottom>
|
||||||
|
Kategorie
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<Box sx={{ borderRadius: '10px', p: 2, border: '1px solid', borderColor: grey[300] }}>
|
||||||
|
<CategoryTree
|
||||||
|
value={article.category}
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
article={article}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<Typography variant="subtitle1" component="div" gutterBottom>
|
||||||
|
Scors
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<Stack direction="row" spacing={2}>
|
||||||
|
<Item>
|
||||||
|
<Select
|
||||||
|
fullWidth
|
||||||
|
labelId="nutriSelect"
|
||||||
|
id="nutri"
|
||||||
|
value={article.nutritionGrade === null ? '' : article.nutritionGrade}
|
||||||
|
label="Nutri-Score"
|
||||||
|
onChange={(e) => {const value = e.target.value;
|
||||||
|
//setNutritionGrade(typeof value === 'string' ? value.split(',') : value);
|
||||||
|
handleArticleChangeAPI(e,'nutritionGrade', value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{grades.map((grade) => (
|
||||||
|
<MenuItem
|
||||||
|
key={grade}
|
||||||
|
value={grade}
|
||||||
|
//style={getStyles(name, personName, theme)}
|
||||||
|
>
|
||||||
|
{grade}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
<img width={'100%'} src={"http://127.0.0.1:8080/Nutri-score-"+article.nutritionGrade+".svg"} alt="NutriScore"/>
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<Select
|
||||||
|
fullWidth
|
||||||
|
labelId="nutriSelect"
|
||||||
|
id="nova"
|
||||||
|
value={article.novaGroup === null ? '' : article.novaGroup}
|
||||||
|
label="NovaGroup"
|
||||||
|
onChange={(e) => {const value = e.target.value;
|
||||||
|
//setNovaGroup(typeof value === 'string' ? value.split(',') : value);
|
||||||
|
handleArticleChangeAPI(e,'novaGroup', value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{novas.map((grade) => (
|
||||||
|
<MenuItem
|
||||||
|
key={grade}
|
||||||
|
value={grade}
|
||||||
|
//style={getStyles(name, personName, theme)}
|
||||||
|
>
|
||||||
|
{grade}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
<img width={'100%'} src={"http://127.0.0.1:8080/nova-group-"+article.novaGroup+".svg"} alt="NovaGroup"/>
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<Select
|
||||||
|
fullWidth
|
||||||
|
labelId="nutriSelect"
|
||||||
|
id="eco"
|
||||||
|
value={article.ecoGrade === null ? '' : article.ecoGrade}
|
||||||
|
label="EcoGrade"
|
||||||
|
onChange={(e) => {const value = e.target.value;
|
||||||
|
//setEcoGrade(typeof value === 'string' ? value.split(',') : value);
|
||||||
|
handleArticleChangeAPI(e,'ecoGrade', value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{grades.map((grade) => (
|
||||||
|
<MenuItem
|
||||||
|
key={grade}
|
||||||
|
value={grade}
|
||||||
|
//style={getStyles(name, personName, theme)}
|
||||||
|
>
|
||||||
|
{grade}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
<img width={'100%'} src={"http://127.0.0.1:8080/Eco-score-"+article.ecoGrade+".svg"} alt="EcoGrade"/>
|
||||||
|
</Item>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
{/*-----------------------------------------------------------------------------------*/}
|
||||||
|
{/*-----------------------------------------------------------------------------------*/}
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<Typography variant="h4" component="div" gutterBottom textAlign="center">
|
||||||
|
Inhaltsstoffe
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={4}>
|
||||||
|
<PictureCard
|
||||||
|
type="Bild der Inhaltsstoffe"
|
||||||
|
article={article}
|
||||||
|
pictureType="ingredientsImage"
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
>
|
||||||
|
</PictureCard>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={8}>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
{/*
|
||||||
|
<ListFieldApi
|
||||||
|
apiURL="/article/ingrediences"
|
||||||
|
titleName="Inhaltsstoffe"
|
||||||
|
addName="Zutat"
|
||||||
|
multiple={true}
|
||||||
|
value={article.ingredients}
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
article={article}
|
||||||
|
fieldName={'ingredients'}
|
||||||
|
/>
|
||||||
|
*/}
|
||||||
|
<IngredienceDataGrid
|
||||||
|
articleId={article.pk}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<ListFieldApi
|
||||||
|
apiURL="/article/allergenes/"
|
||||||
|
titleName="Allergene"
|
||||||
|
addName="Zutat"
|
||||||
|
multiple={true}
|
||||||
|
value={article.allergenes}
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
article={article}
|
||||||
|
fieldName={'allergenes'}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<ListFieldApi
|
||||||
|
apiURL="/article/traces/"
|
||||||
|
titleName="Spuren"
|
||||||
|
addName="Zutat"
|
||||||
|
multiple={true}
|
||||||
|
value={article.traces}
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
article={article}
|
||||||
|
fieldName={'traces'}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<ListFieldApi
|
||||||
|
apiURL="/article/embs/"
|
||||||
|
titleName="EMB Nummern"
|
||||||
|
addName="Nummer"
|
||||||
|
multiple={true}
|
||||||
|
value={article.embs}
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
article={article}
|
||||||
|
fieldName={'embs'}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<ListFieldApi
|
||||||
|
apiURL="/article/manufacturingPlaces/"
|
||||||
|
titleName="Ort der Herstellung"
|
||||||
|
addName="Ort"
|
||||||
|
multiple={true}
|
||||||
|
value={article.manufacturingPlaces}
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
article={article}
|
||||||
|
fieldName={'manufacturingPlaces'}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<ListFieldApi
|
||||||
|
apiURL="/article/originIngredients/"
|
||||||
|
titleName="Herkunft der Inhaltsstoffe"
|
||||||
|
addName="Ort"
|
||||||
|
multiple={true}
|
||||||
|
value={article.originIngredients}
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
article={article}
|
||||||
|
fieldName={'originIngredients'}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
{/*-----------------------------------------------------------------------------------*/}
|
||||||
|
{/*-----------------------------------------------------------------------------------*/}
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<Typography variant="h4" component="div" gutterBottom textAlign="center">
|
||||||
|
Nährwertangaben
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={4}>
|
||||||
|
<PictureCard
|
||||||
|
type="Bild der Nährwerte"
|
||||||
|
article={article}
|
||||||
|
pictureType="nutritionImage"
|
||||||
|
onChange={handelArticleChange}
|
||||||
|
>
|
||||||
|
</PictureCard>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={8}>
|
||||||
|
<NutriDataGrid
|
||||||
|
article={article}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<div>
|
||||||
|
{!!snackbar && (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
|
onClose={handleCloseSnackbar}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
>
|
||||||
|
<Alert {...snackbar} onClose={handleCloseSnackbar} />
|
||||||
|
</Snackbar>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ArticleDetails
|
||||||
65
reactFrontend/src/components/ArticleOverview.component.jsx
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
|
||||||
|
//import Button from '@mui/material/Button';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
import Container from '@mui/material/Container';
|
||||||
|
import Grid from '@mui/material/Grid';
|
||||||
|
//import Box from '@mui/material/Box';
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
import ArticleCard from "./articleCard.component";
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
const ArticelOverview = (props) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const [tableData, setTableData] = useState([]);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
axios.get(baseURL+"/articles/")
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
console.log(data)
|
||||||
|
setTableData(data);
|
||||||
|
})
|
||||||
|
},[])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ height: 800, width: '100%' }}>
|
||||||
|
|
||||||
|
<Typography variant="h2" gutterBottom>
|
||||||
|
Übersicht über alle Artikel
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Container maxWidth="xl">
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
direction="row"
|
||||||
|
justify="space-evenly"
|
||||||
|
alignItems="stretch"
|
||||||
|
spacing={2}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
tableData.map(data => (
|
||||||
|
<Grid item
|
||||||
|
key={`GridItem-${data.pk}`} xs={2}
|
||||||
|
>
|
||||||
|
<ArticleCard
|
||||||
|
article={data}
|
||||||
|
navigate={navigate}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</Grid>
|
||||||
|
</Container>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ArticelOverview
|
||||||
193
reactFrontend/src/components/Canvas.component.js
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { useRef, useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
const ReceipeCanvas = props => {
|
||||||
|
|
||||||
|
const canvasRef = useRef(null)
|
||||||
|
const contextRef = useRef(null);
|
||||||
|
|
||||||
|
const { image, myRef, setNewRect, ...rest } = props
|
||||||
|
|
||||||
|
const [isDrawing, setIsDrawing] = useState(false);
|
||||||
|
|
||||||
|
//const [data, setData] = useState(drawData)
|
||||||
|
|
||||||
|
const canvasOffSetX = useRef(null);
|
||||||
|
const canvasOffSetY = useRef(null);
|
||||||
|
const startX = useRef(null);
|
||||||
|
const startY = useRef(null);
|
||||||
|
const rectWidth = useRef(null);
|
||||||
|
const rectHeight = useRef(null);
|
||||||
|
const imgWidth = useRef(null);
|
||||||
|
const imgHeight = useRef(null);
|
||||||
|
|
||||||
|
var ratio;
|
||||||
|
|
||||||
|
const draw = (drawData) => {
|
||||||
|
console.log('draw')
|
||||||
|
//contextRef.current.beginPath();
|
||||||
|
contextRef.current.strokeStyle="red";
|
||||||
|
//contextRef.current.rect(drawData.location_x*ratio,drawData.location_y*ratio,drawData.location_w*ratio,drawData.location_h*ratio);
|
||||||
|
//contextRef.current.stroke();
|
||||||
|
|
||||||
|
const hRatio = contextRef.current.canvas.width / image.width;
|
||||||
|
|
||||||
|
//Clears the entire canvas
|
||||||
|
contextRef.current.clearRect(0, 0, canvasRef.current.width, canvasRef.current.height);
|
||||||
|
|
||||||
|
//Redraw the background image
|
||||||
|
contextRef.current.drawImage(image, 0,0,
|
||||||
|
image.width,
|
||||||
|
image.height,
|
||||||
|
0,0,
|
||||||
|
image.width*hRatio,
|
||||||
|
image.height*hRatio);
|
||||||
|
|
||||||
|
contextRef.current.strokeRect(drawData.location_x*hRatio,drawData.location_y*hRatio,drawData.location_w*hRatio,drawData.location_h*hRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
const drawImage = async (image) => {
|
||||||
|
console.log('Draw image fkt')
|
||||||
|
/*
|
||||||
|
var img = new Image();
|
||||||
|
img.onload = function(){
|
||||||
|
imgWidth.current = img.naturalWidth
|
||||||
|
imgHeight.current = img.naturalHeight;
|
||||||
|
//console.log("width,height:", img.width, img.height);
|
||||||
|
//console.log("offsetW,offsetH:", img.offsetWidth, img.offsetHeight);
|
||||||
|
}
|
||||||
|
img.src = image.src;
|
||||||
|
*/
|
||||||
|
await image.decode()
|
||||||
|
contextRef.current.clearRect(0, 0, contextRef.current.canvas.width, contextRef.current.canvas.height);
|
||||||
|
|
||||||
|
ratio = contextRef.current.canvas.width / image.width;
|
||||||
|
contextRef.current.canvas.height = image.height*ratio;
|
||||||
|
contextRef.current.drawImage(image, 0,0,
|
||||||
|
image.width,
|
||||||
|
image.height,
|
||||||
|
0,0,
|
||||||
|
image.width*ratio,
|
||||||
|
image.height*ratio);
|
||||||
|
|
||||||
|
|
||||||
|
console.log(image.width, ratio, contextRef.current.canvas.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
myRef.current.draw = draw
|
||||||
|
myRef.current.drawImage = drawImage
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const canvas = canvasRef.current
|
||||||
|
const context = canvas.getContext('2d')
|
||||||
|
context.canvas.width = 300
|
||||||
|
|
||||||
|
context.clearRect(0, 0, context.canvas.width, context.canvas.height);
|
||||||
|
ratio = context.canvas.width / image.width ;
|
||||||
|
context.canvas.height = image.height*ratio;
|
||||||
|
|
||||||
|
context.drawImage(image, 0,0,
|
||||||
|
image.width,
|
||||||
|
image.height,
|
||||||
|
0,0,
|
||||||
|
image.width*ratio,
|
||||||
|
image.height*ratio);
|
||||||
|
|
||||||
|
//draw(context,hRatio);
|
||||||
|
|
||||||
|
contextRef.current = context;
|
||||||
|
|
||||||
|
console.log('useeffect',image)
|
||||||
|
},[image])
|
||||||
|
|
||||||
|
const startDrawingRectangle = ({nativeEvent}) => {
|
||||||
|
nativeEvent.preventDefault();
|
||||||
|
nativeEvent.stopPropagation();
|
||||||
|
|
||||||
|
const canvasOffSet = canvasRef.current.getBoundingClientRect();
|
||||||
|
canvasOffSetX.current = canvasOffSet.left;
|
||||||
|
canvasOffSetY.current = canvasOffSet.top;
|
||||||
|
|
||||||
|
startX.current = nativeEvent.clientX - canvasOffSetX.current;
|
||||||
|
startY.current = nativeEvent.clientY - canvasOffSetY.current;
|
||||||
|
console.log('#nativ',nativeEvent.clientX,nativeEvent.clientY)
|
||||||
|
setIsDrawing(true);
|
||||||
|
console.log("Start drawing")
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawRectangle = ({nativeEvent}) => {
|
||||||
|
if (!isDrawing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nativeEvent.preventDefault();
|
||||||
|
nativeEvent.stopPropagation();
|
||||||
|
|
||||||
|
const newMouseX = nativeEvent.clientX - canvasOffSetX.current;
|
||||||
|
const newMouseY = nativeEvent.clientY - canvasOffSetY.current;
|
||||||
|
|
||||||
|
rectWidth.current = newMouseX - startX.current;
|
||||||
|
rectHeight.current = newMouseY - startY.current;
|
||||||
|
|
||||||
|
contextRef.current.strokeStyle="red";
|
||||||
|
|
||||||
|
//Clears the entire canvas
|
||||||
|
contextRef.current.clearRect(0, 0, canvasRef.current.width, canvasRef.current.height);
|
||||||
|
|
||||||
|
//Redraw the background image
|
||||||
|
const hRatio = contextRef.current.canvas.width / image.width;
|
||||||
|
contextRef.current.drawImage(image, 0,0,
|
||||||
|
image.width,
|
||||||
|
image.height,
|
||||||
|
0,0,
|
||||||
|
image.width*hRatio,
|
||||||
|
image.height*hRatio);
|
||||||
|
|
||||||
|
contextRef.current.strokeRect(startX.current, startY.current, rectWidth.current, rectHeight.current);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const stopDrawingRectangle = ({nativeEvent}) => {
|
||||||
|
nativeEvent.preventDefault();
|
||||||
|
nativeEvent.stopPropagation();
|
||||||
|
|
||||||
|
const hRatio = contextRef.current.canvas.width / image.width;
|
||||||
|
console.log({location_x: startX.current/hRatio, location_y: startY.current/hRatio, location_w: rectWidth.current/hRatio,location_h: rectHeight.current/hRatio})
|
||||||
|
if (startX.current/hRatio < 0){
|
||||||
|
startX.current = 0;
|
||||||
|
}
|
||||||
|
if ((rectWidth.current < 0) && (rectHeight.current > 0)) {
|
||||||
|
setNewRect({location_x: (startX.current+rectWidth.current)/hRatio, location_y: startY.current/hRatio, location_w: -rectWidth.current/hRatio,location_h: rectHeight.current/hRatio});
|
||||||
|
}
|
||||||
|
else if ((rectWidth.current > 0) && (rectHeight.current < 0)) {
|
||||||
|
setNewRect({location_x: startX.current/hRatio, location_y: (startY.current+rectHeight.current)/hRatio, location_w: rectWidth.current/hRatio,location_h: -rectHeight.current/hRatio});
|
||||||
|
}
|
||||||
|
else if ((rectHeight.current < 0) && (rectWidth.current < 0)) {
|
||||||
|
console.log('<<')
|
||||||
|
setNewRect({location_x: (startX.current+rectWidth.current)/hRatio, location_y: (startY.current+rectHeight.current)/hRatio, location_w: -rectWidth.current/hRatio,location_h: -rectHeight.current/hRatio});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setNewRect({location_x: startX.current/hRatio, location_y: startY.current/hRatio, location_w: rectWidth.current/hRatio,location_h: rectHeight.current/hRatio});
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsDrawing(false);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
return <canvas
|
||||||
|
ref={canvasRef}
|
||||||
|
onMouseDown={startDrawingRectangle}
|
||||||
|
onMouseMove={drawRectangle}
|
||||||
|
onMouseUp={stopDrawingRectangle}
|
||||||
|
//onMouseLeave={stopDrawingRectangle}
|
||||||
|
{...rest}>
|
||||||
|
</canvas>
|
||||||
|
}
|
||||||
|
|
||||||
|
ReceipeCanvas.defaultProps = {
|
||||||
|
myRef: {current: {}}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ReceipeCanvas
|
||||||
94
reactFrontend/src/components/CategoryTree.component.js
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import {Snackbar, Alert} from '@mui/material';
|
||||||
|
|
||||||
|
import TreeView from '@mui/lab/TreeView';
|
||||||
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||||
|
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
||||||
|
import TreeItem from '@mui/lab/TreeItem';
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
const apiURL = "/article/categories/"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const CategoryTree = (props) => {
|
||||||
|
const { value, article, onChange } = props;
|
||||||
|
|
||||||
|
const [categories, setCategories] = useState({id: 'root', data: {id: -1, name: ''}});
|
||||||
|
const [snackbar, setSnackbar] = useState(null);
|
||||||
|
|
||||||
|
const renderTree = (nodes) => (
|
||||||
|
<TreeItem key={nodes.id} nodeId={nodes.id.toString()} label={nodes.data.name}>
|
||||||
|
{Array.isArray(nodes.children)
|
||||||
|
? nodes.children.map((node) => renderTree(node))
|
||||||
|
: null}
|
||||||
|
</TreeItem>
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleCloseSnackbar = () => setSnackbar(null);
|
||||||
|
|
||||||
|
const handleNodeSelect = async (e, nodeid) => {
|
||||||
|
try {
|
||||||
|
//var completeCategory = {};
|
||||||
|
const completeCategory = await axios.get(baseURL+"/article/categories/"+nodeid);
|
||||||
|
|
||||||
|
//console.log(completeCategory.data);
|
||||||
|
const newArticle = { ...article, 'category': completeCategory.data};
|
||||||
|
const sendArticle = await axios.put(baseURL+"/article/"+article.pk, {
|
||||||
|
article: newArticle
|
||||||
|
});
|
||||||
|
//console.log(newArticle)
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
|
||||||
|
onChange(newArticle);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
axios.get(baseURL+apiURL)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
setCategories(data);
|
||||||
|
//console.log(data);
|
||||||
|
})
|
||||||
|
|
||||||
|
},[])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ height: 350, width: '100%' }}>
|
||||||
|
<TreeView
|
||||||
|
//aria-label="rich object"
|
||||||
|
defaultExpanded={value === null ? [] : value.ancestorIds.map(x => String(x)) }
|
||||||
|
defaultExpandIcon={<ChevronRightIcon />}
|
||||||
|
defaultCollapseIcon={<ExpandMoreIcon />}
|
||||||
|
defaultSelected={value === null ? [''] : value.id.toString()}
|
||||||
|
onNodeSelect={handleNodeSelect}
|
||||||
|
sx={{ height: 350, flexGrow: 1, overflowY: 'auto' }}
|
||||||
|
>
|
||||||
|
{renderTree(categories)}
|
||||||
|
</TreeView>
|
||||||
|
{!!snackbar && (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
|
onClose={handleCloseSnackbar}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
>
|
||||||
|
<Alert {...snackbar} onClose={handleCloseSnackbar} />
|
||||||
|
</Snackbar>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CategoryTree
|
||||||
|
|
||||||
17
reactFrontend/src/components/Home.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import React, { Component } from "react";
|
||||||
|
|
||||||
|
export default class Home extends Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div className="Home">
|
||||||
|
<div className="lander">
|
||||||
|
<h1>Home page</h1>
|
||||||
|
<p>A simple app showing react button click navigation</p>
|
||||||
|
<form>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
362
reactFrontend/src/components/IngredienceDataGrid.component.jsx
Normal file
@ -0,0 +1,362 @@
|
|||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
//import { useNavigate, useLocation } from 'react-router-dom';
|
||||||
|
import { Button } from '@mui/material'
|
||||||
|
|
||||||
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
|
import DeleteIcon from '@mui/icons-material/DeleteOutlined';
|
||||||
|
|
||||||
|
import { DataGrid, GridToolbarContainer, GridActionsCellItem } from '@mui/x-data-grid';
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
|
import Grid from '@mui/material/Grid';
|
||||||
|
import Dialog from '@mui/material/Dialog';
|
||||||
|
import TextField from '@mui/material/TextField';
|
||||||
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
||||||
|
import Checkbox from '@mui/material/Checkbox';
|
||||||
|
import DialogTitle from '@mui/material/DialogTitle';
|
||||||
|
import DialogContentText from '@mui/material/DialogContentText';
|
||||||
|
import DialogActions from '@mui/material/DialogActions';
|
||||||
|
import DialogContent from '@mui/material/DialogContent';
|
||||||
|
|
||||||
|
import ListFieldApiwoArticle from "./ListFieldApiwoArticle.component"
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
const apiURL = "/article/ingrediences/"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function EditToolbar(props) {
|
||||||
|
const { setTableData, articleId, setOpenAddDialog } = props;
|
||||||
|
|
||||||
|
const handleNewEntryClick = async () => {
|
||||||
|
|
||||||
|
const newValue = { ingredient: {id: -1, name: 'Bitte auswählen'}, percent: null, isNew: true, article: articleId };
|
||||||
|
const receivedData = await axios.post(baseURL+"/article/articleIngrediences/"+articleId, {
|
||||||
|
newValue,
|
||||||
|
})
|
||||||
|
|
||||||
|
//console.log(receivedData)
|
||||||
|
const newRow = { id: receivedData.data.id, ingredient: {id: -1, name: 'Bitte auswählen'}, percent: receivedData.data.percent, isNew: true, article: receivedData.data.article, position: receivedData.data.position };
|
||||||
|
|
||||||
|
setTableData((oldRows) => [...oldRows, newRow]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNewIngredientClick = () => {
|
||||||
|
setOpenAddDialog(true);
|
||||||
|
/*
|
||||||
|
const newValue = { packaging_id: {id: -1, name: 'Bitte auswählen'}, weight: 0, isNew: true, article_id: articleId };
|
||||||
|
const receivedData = await axios.post(baseURL+"/article/articleIngrediences/"+articleId, {
|
||||||
|
newValue,
|
||||||
|
})
|
||||||
|
|
||||||
|
//console.log(receivedData)
|
||||||
|
const newRow = { id: receivedData.data.id, ingredient: {id: -1, name: 'Bitte auswählen'}, percent: receivedData.data.percent, isNew: true, article: receivedData.data.article, position: receivedData.data.positio };
|
||||||
|
|
||||||
|
setTableData((oldRows) => [...oldRows, newRow]);
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<GridToolbarContainer>
|
||||||
|
<Button color="primary" startIcon={<AddIcon />} onClick={handleNewEntryClick}>
|
||||||
|
Neuer Eintrag
|
||||||
|
</Button>
|
||||||
|
<Button color="primary" startIcon={<AddIcon />} onClick={handleNewIngredientClick}>
|
||||||
|
Neue Zutat
|
||||||
|
</Button>
|
||||||
|
</GridToolbarContainer>
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditToolbar.propTypes = {
|
||||||
|
setTableData: PropTypes.func.isRequired,
|
||||||
|
setOpenAddDialog: PropTypes.func.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
const IngredienceDataGrid = (props) => {
|
||||||
|
const { articleId } = props;
|
||||||
|
|
||||||
|
//list contains all ingrediences
|
||||||
|
const [list, setList] = useState([{id: -1, name: '', subIngredients: []}]);
|
||||||
|
const [tableData, setTableData] = useState([{id: -1, ingredient: {id: -1, name: ''}, percent: null, article: -1, position: -1}]);
|
||||||
|
const [snackbar, setSnackbar] = useState(null);
|
||||||
|
|
||||||
|
const [openAddDialog, setOpenAddDialog] = useState(false);
|
||||||
|
|
||||||
|
const [newIngredient, setNewIngredient] = useState({name: '', allergenes: [], vegan: false, additive: false, vegetarian: false, palmoilfree: true, subIngredients: [], eNumber: ''});
|
||||||
|
|
||||||
|
const columnsIngrediences = [
|
||||||
|
{
|
||||||
|
field: 'position',
|
||||||
|
headerName: 'Pos.',
|
||||||
|
width: 50,
|
||||||
|
editable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'ingredient',
|
||||||
|
headerName: 'Name',
|
||||||
|
flex: 1,
|
||||||
|
type: 'singleSelect',
|
||||||
|
valueOptions: list,
|
||||||
|
getOptionValue: (value) => value.id,
|
||||||
|
getOptionLabel: (value) => {if (value.subIngredients.length === 0) {
|
||||||
|
return value.name
|
||||||
|
} else {
|
||||||
|
return value.name + ' ('+value.subIngredients.map(x => x.name).join(', ')+')'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
editable: true,
|
||||||
|
valueGetter: (params) => {try {return params.row.ingredient.id;} catch {return '';} },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'percent',
|
||||||
|
headerName: 'Anteil an Gesamtmasse',
|
||||||
|
type: 'number',
|
||||||
|
width:170,
|
||||||
|
editable: true,
|
||||||
|
valueFormatter: (params) => {
|
||||||
|
if (params.value == null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return `${params.value} %`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'actions',
|
||||||
|
type: 'actions',
|
||||||
|
headerName: 'Aktionen',
|
||||||
|
width: 100,
|
||||||
|
cellClassName: 'actions',
|
||||||
|
getActions: ({ id }) => {
|
||||||
|
return [
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<DeleteIcon />}
|
||||||
|
label="Delete"
|
||||||
|
onClick={(e) => handleDeleteClick(id,e)}
|
||||||
|
color="inherit"
|
||||||
|
/>,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const findId = (idToLookFor) => {
|
||||||
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
if (list[i].name === idToLookFor) {
|
||||||
|
return(list[i].id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCloseSnackbar = () => setSnackbar(null);
|
||||||
|
|
||||||
|
//Anscheinend ist es notwendig das event e zu übergeben, ansonsten passieren komische Dinge (kein async, multiple trigger beim rendern etc)
|
||||||
|
const handleDeleteClick = async (id,e) => {
|
||||||
|
const newData = tableData.filter((row) => row.id !== id);
|
||||||
|
//console.log('Delete clicked')
|
||||||
|
//console.log(id)
|
||||||
|
//console.log(e)
|
||||||
|
try {
|
||||||
|
const receivedData = await axios.delete(baseURL+"/article/articleIngrediences/"+articleId, {
|
||||||
|
data: id,
|
||||||
|
})
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
setTableData(newData);
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const processRowUpdate = React.useCallback( async (newRow, oldRow) => {
|
||||||
|
console.log(newRow)
|
||||||
|
const ingredient = list.find(x => x.id === newRow.ingredient);
|
||||||
|
const updatedRow = {'id': newRow.id, 'ingredient': ingredient, 'position': newRow.position, 'isNew': false, 'article': articleId, 'percent': newRow.percent};
|
||||||
|
const newData = tableData.map((row) => (row.id === newRow.id ? updatedRow : row));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.put(baseURL+"/article/articleIngrediences/"+articleId, {
|
||||||
|
updatedRow
|
||||||
|
});
|
||||||
|
|
||||||
|
//console.log(response);
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
|
||||||
|
setTableData(newData);
|
||||||
|
//onChange(newData);
|
||||||
|
return updatedRow;
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
return oldRow;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
//const handleProcessRowUpdateError = React.useCallback((error) => {
|
||||||
|
// setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
//}, []);
|
||||||
|
const handleClose = () => {
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleAdd = async() => {
|
||||||
|
console.log(newIngredient)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ans = await axios.post(baseURL+"/article/ingrediences/", {
|
||||||
|
newIngredient,
|
||||||
|
})
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
setOpenAddDialog(false);
|
||||||
|
setNewIngredient({name: '', allergenes: [], vegan: false, additive: false, vegetarian: false, palmoilfree: true, subIngredients: [], eNumber: ''});
|
||||||
|
|
||||||
|
setList(list.concat(ans.data));
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
axios.get(baseURL+apiURL)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
console.log(data);
|
||||||
|
setList(data);
|
||||||
|
})
|
||||||
|
|
||||||
|
axios.get(baseURL+"/article/articleIngrediences/"+articleId)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
//Add id for each element for displaying in Data Grid
|
||||||
|
//data.forEach((item, i) => {
|
||||||
|
// item.id = i + 1;
|
||||||
|
//});
|
||||||
|
|
||||||
|
setTableData(data);
|
||||||
|
console.log("Fetching ingrediences data")
|
||||||
|
console.log(data)
|
||||||
|
})
|
||||||
|
|
||||||
|
},[])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ height: 350, width: '100%' }}>
|
||||||
|
<DataGrid
|
||||||
|
rows={tableData}
|
||||||
|
columns={columnsIngrediences}
|
||||||
|
pageSize={10}
|
||||||
|
editMode="row"
|
||||||
|
//getRowId={(row) => row.internalId}
|
||||||
|
processRowUpdate={processRowUpdate}
|
||||||
|
//onProcessRowUpdateError={handleProcessRowUpdateError}
|
||||||
|
experimentalFeatures={{ newEditingApi: true }}
|
||||||
|
components={{
|
||||||
|
Toolbar: EditToolbar,
|
||||||
|
}}
|
||||||
|
componentsProps={{
|
||||||
|
toolbar: { setTableData, articleId, setOpenAddDialog },
|
||||||
|
}}
|
||||||
|
|
||||||
|
/>
|
||||||
|
<Dialog open={openAddDialog} onClose={handleClose}>
|
||||||
|
<DialogTitle>Zutat hinzufügen</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogContentText>
|
||||||
|
Füge eine neue Zutat hinzu:
|
||||||
|
</DialogContentText>
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="nameField"
|
||||||
|
//defaultValue={name != null ? name : ""}
|
||||||
|
value={newIngredient.name}
|
||||||
|
onChange={(e) => setNewIngredient({ ...newIngredient, name: e.target.value})}
|
||||||
|
//error={(article.name.length === 0)}
|
||||||
|
label="Name"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
//onBlur={(e) => handleArticleChangeAPI(e,'name', e.target.value)}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<ListFieldApiwoArticle
|
||||||
|
apiURL="/article/allergenes/"
|
||||||
|
titleName="Allergene"
|
||||||
|
addName="Zutat"
|
||||||
|
multiple={true}
|
||||||
|
value={newIngredient.allergenes}
|
||||||
|
onChange={(e) => setNewIngredient({ ...newIngredient, allergenes: e})}
|
||||||
|
addNew={false}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<FormControlLabel control={<Checkbox checked={newIngredient.vegan} onChange={(e) => setNewIngredient({ ...newIngredient, vegan: e.target.checked})} />} label="vegan?" />
|
||||||
|
<FormControlLabel control={<Checkbox checked={newIngredient.vegetarian} onChange={(e) => setNewIngredient({ ...newIngredient, vegetarian: e.target.checked})} />} label="vegetarisch?" />
|
||||||
|
<FormControlLabel control={<Checkbox checked={newIngredient.palmoilfree} onChange={(e) => setNewIngredient({ ...newIngredient, palmoilfree: e.target.checked})} />} label="Palmölfrei?" />
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<FormControlLabel control={<Checkbox checked={newIngredient.additive} onChange={(e) => setNewIngredient({ ...newIngredient, additive: e.target.checked})} />} label="Zusatzstoff?" />
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="EnumberField"
|
||||||
|
disabled={!newIngredient.additive}
|
||||||
|
value={newIngredient.eNumber}
|
||||||
|
onChange={(e) => setNewIngredient({ ...newIngredient, eNumber: e.target.value})}
|
||||||
|
error={(newIngredient.eNumber.length === 0 && newIngredient.additive)}
|
||||||
|
label="E-Nummer"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<ListFieldApiwoArticle
|
||||||
|
apiURL="/article/ingrediences/"
|
||||||
|
titleName="Inhaltsstoffe"
|
||||||
|
addName="Zutat"
|
||||||
|
multiple={true}
|
||||||
|
value={newIngredient.subIngredients}
|
||||||
|
onChange={(e) => setNewIngredient({ ...newIngredient, subIngredients: e})}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={() => setOpenAddDialog(false)}>Abbrechen</Button>
|
||||||
|
<Button onClick={handleAdd}>Hinzufügen</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
{!!snackbar && (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
|
onClose={handleCloseSnackbar}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
>
|
||||||
|
<Alert {...snackbar} onClose={handleCloseSnackbar} />
|
||||||
|
</Snackbar>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IngredienceDataGrid
|
||||||
152
reactFrontend/src/components/ListFieldApi.component.js
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import axios from 'axios';
|
||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
|
||||||
|
import {TextField, Autocomplete, createFilterOptions} from '@mui/material'
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
|
|
||||||
|
const filter = createFilterOptions();
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
const ListFieldApi = (props) => {
|
||||||
|
|
||||||
|
const { apiURL, titleName, addName, multiple, value, onChange, sx, article, fieldName } = props
|
||||||
|
|
||||||
|
const [list, setList] = useState([""]);
|
||||||
|
const [inputValue, setInputValue] = React.useState('')
|
||||||
|
const [snackbar, setSnackbar] = useState(null);
|
||||||
|
|
||||||
|
const handleAdd = async(newValue) => {
|
||||||
|
const send = await axios.post(baseURL+apiURL+'/', {
|
||||||
|
name: newValue,
|
||||||
|
})
|
||||||
|
|
||||||
|
const rec = await axios.get(baseURL+apiURL)
|
||||||
|
|
||||||
|
setList(rec.data);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCloseSnackbar = () => setSnackbar(null);
|
||||||
|
|
||||||
|
const handleOnChange = async (event, newValue) => {
|
||||||
|
//Neuer Wert ist letztes Array element
|
||||||
|
//console.log(event)
|
||||||
|
//console.log(newValue)
|
||||||
|
if (newValue === null){
|
||||||
|
}
|
||||||
|
// Fall das wir mehr als einen Eintrag haben
|
||||||
|
else if (Array.isArray(newValue)) {
|
||||||
|
if (!(newValue.length === 0)){
|
||||||
|
// Wenn letztes array element nicht in der Liste der möglichen, dann haben wir ein neues Element was wir hinzufügen
|
||||||
|
if (!list.some(item => item.name === newValue[newValue.length - 1].name)) {
|
||||||
|
handleAdd(newValue[newValue.length - 1].inputValue);
|
||||||
|
newValue[newValue.length - 1].name = newValue[newValue.length - 1].inputValue;
|
||||||
|
delete newValue[newValue.length - 1]["inputValue"];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Hinzufügen des ersten Elements
|
||||||
|
else{
|
||||||
|
if (!list.some(item => item.name === newValue.name)) {
|
||||||
|
handleAdd(newValue.inputValue);
|
||||||
|
newValue.name = newValue.inputValue;
|
||||||
|
delete newValue["inputValue"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newArticle = { ...article, [fieldName]: newValue};
|
||||||
|
const sendArticle = await axios.put(baseURL+"/article/"+article.pk, {
|
||||||
|
article: newArticle
|
||||||
|
});
|
||||||
|
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
|
||||||
|
onChange(newArticle);
|
||||||
|
}
|
||||||
|
catch(error){
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
if (Array.isArray(newValue)) {
|
||||||
|
newValue = newValue.slice(0, -1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newValue = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
axios.get(baseURL+apiURL)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
setList(data);
|
||||||
|
//console.log(data)
|
||||||
|
})
|
||||||
|
|
||||||
|
},[])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Autocomplete
|
||||||
|
multiple={multiple}
|
||||||
|
id="tags-standard"
|
||||||
|
options={list}
|
||||||
|
sx={sx}
|
||||||
|
getOptionLabel={(option) => {
|
||||||
|
if (option.name === undefined){
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return option.name
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
isOptionEqualToValue={(option, value) => option.name === value.name}
|
||||||
|
inputValue={inputValue}
|
||||||
|
onInputChange={(_, newInputValue) => {
|
||||||
|
setInputValue(newInputValue)
|
||||||
|
}}
|
||||||
|
//defaultValue={[]}
|
||||||
|
value={value}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
variant="standard"
|
||||||
|
label={titleName}
|
||||||
|
placeholder={addName}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
onChange={handleOnChange}
|
||||||
|
filterOptions={(options, params) => {
|
||||||
|
const filtered = filter(options, params);
|
||||||
|
|
||||||
|
if (params.inputValue !== '') {
|
||||||
|
filtered.push({
|
||||||
|
inputValue: params.inputValue,
|
||||||
|
name: `Add "${params.inputValue}"`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered;
|
||||||
|
}}
|
||||||
|
renderOption={(props, option) => <li {...props}>{option.name}</li>}
|
||||||
|
|
||||||
|
/>
|
||||||
|
{!!snackbar && (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
|
onClose={handleCloseSnackbar}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
>
|
||||||
|
<Alert {...snackbar} onClose={handleCloseSnackbar} />
|
||||||
|
</Snackbar>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ListFieldApi
|
||||||
154
reactFrontend/src/components/ListFieldApiwoArticle.component.js
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import axios from 'axios';
|
||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
|
||||||
|
import {TextField, Autocomplete, createFilterOptions} from '@mui/material'
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
|
|
||||||
|
const filter = createFilterOptions();
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
const ListFieldApiwoArticle = (props) => {
|
||||||
|
|
||||||
|
const { apiURL, titleName, addName, multiple, value, onChange, sx, addNew} = props
|
||||||
|
|
||||||
|
const [list, setList] = useState([""]);
|
||||||
|
const [inputValue, setInputValue] = React.useState('')
|
||||||
|
const [snackbar, setSnackbar] = useState(null);
|
||||||
|
|
||||||
|
const handleAdd = async(newValue) => {
|
||||||
|
const send = await axios.post(baseURL+apiURL, {
|
||||||
|
name: newValue,
|
||||||
|
})
|
||||||
|
|
||||||
|
const rec = await axios.get(baseURL+apiURL)
|
||||||
|
|
||||||
|
setList(rec.data);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCloseSnackbar = () => setSnackbar(null);
|
||||||
|
|
||||||
|
const handleOnChange = async (event, newValue) => {
|
||||||
|
//Neuer Wert ist letztes Array element
|
||||||
|
//console.log(event)
|
||||||
|
//console.log(newValue)
|
||||||
|
if (newValue === null){
|
||||||
|
}
|
||||||
|
// Fall das wir mehr als einen Eintrag haben
|
||||||
|
else if (Array.isArray(newValue)) {
|
||||||
|
if (!(newValue.length === 0)){
|
||||||
|
// Wenn letztes array element nicht in der Liste der möglichen, dann haben wir ein neues Element was wir hinzufügen
|
||||||
|
if (!list.some(item => item.name === newValue[newValue.length - 1].name)) {
|
||||||
|
handleAdd(newValue[newValue.length - 1].inputValue);
|
||||||
|
newValue[newValue.length - 1].name = newValue[newValue.length - 1].inputValue;
|
||||||
|
delete newValue[newValue.length - 1]["inputValue"];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Hinzufügen des ersten Elements
|
||||||
|
else{
|
||||||
|
if (!list.some(item => item.name === newValue.name)) {
|
||||||
|
handleAdd(newValue.inputValue);
|
||||||
|
newValue.name = newValue.inputValue;
|
||||||
|
delete newValue["inputValue"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
const newArticle = { ...article, [fieldName]: newValue};
|
||||||
|
const sendArticle = await axios.put(baseURL+"/article/"+article.pk, {
|
||||||
|
article: newArticle
|
||||||
|
});
|
||||||
|
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
*/
|
||||||
|
onChange(newValue);
|
||||||
|
/*
|
||||||
|
}
|
||||||
|
catch(error){
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
if (Array.isArray(newValue)) {
|
||||||
|
newValue = newValue.slice(0, -1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newValue = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
axios.get(baseURL+apiURL)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
setList(data);
|
||||||
|
console.log(data)
|
||||||
|
})
|
||||||
|
|
||||||
|
},[])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Autocomplete
|
||||||
|
multiple={multiple}
|
||||||
|
id="tags-standard"
|
||||||
|
options={list}
|
||||||
|
sx={sx}
|
||||||
|
getOptionLabel={(option) => {
|
||||||
|
if (option.name === undefined){
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return option.name
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
isOptionEqualToValue={(option, value) => option.name === value.name}
|
||||||
|
inputValue={inputValue}
|
||||||
|
onInputChange={(_, newInputValue) => {
|
||||||
|
setInputValue(newInputValue)
|
||||||
|
}}
|
||||||
|
//defaultValue={[]}
|
||||||
|
value={value}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
variant="standard"
|
||||||
|
label={titleName}
|
||||||
|
placeholder={addName}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
onChange={handleOnChange}
|
||||||
|
filterOptions={(options, params) => {
|
||||||
|
const filtered = filter(options, params);
|
||||||
|
|
||||||
|
if (params.inputValue !== '' && addNew) {
|
||||||
|
filtered.push({
|
||||||
|
inputValue: params.inputValue,
|
||||||
|
name: `Add "${params.inputValue}"`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered;
|
||||||
|
}}
|
||||||
|
renderOption={(props, option) => <li {...props}>{option.name}</li>}
|
||||||
|
|
||||||
|
/>
|
||||||
|
{!!snackbar && (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
|
onClose={handleCloseSnackbar}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
>
|
||||||
|
<Alert {...snackbar} onClose={handleCloseSnackbar} />
|
||||||
|
</Snackbar>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ListFieldApiwoArticle
|
||||||
271
reactFrontend/src/components/MarketDetail.component.js
Normal file
@ -0,0 +1,271 @@
|
|||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import { Grid, TextField } from '@mui/material'
|
||||||
|
import Button from '@mui/material/Button'
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
|
import Dialog from '@mui/material/Dialog';
|
||||||
|
import DialogTitle from '@mui/material/DialogTitle';
|
||||||
|
import DialogContent from '@mui/material/DialogContent';
|
||||||
|
import DialogActions from '@mui/material/DialogActions';
|
||||||
|
import Select from '@mui/material/Select';
|
||||||
|
import MenuItem from '@mui/material/MenuItem';
|
||||||
|
import Checkbox from '@mui/material/Checkbox';
|
||||||
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
const MarketDetail = (props) => {
|
||||||
|
const [openExchangeDialog, setOpenExchangeDialog] = useState(false);
|
||||||
|
const [exchangeMarket, setExchangeMarket] = useState({oldMarket: {}, newMarket: {name: '', street: '', street_number: 0, zip_code: '', city: '', phone:''}, deleteOld: false});
|
||||||
|
const [markets, setMarkets] = useState([]);
|
||||||
|
const [snackbar, setSnackbar] = useState(null);
|
||||||
|
|
||||||
|
const [market, setMarket] = useState({
|
||||||
|
name: '',
|
||||||
|
street: '',
|
||||||
|
street_number: 0,
|
||||||
|
zip_code: '',
|
||||||
|
city: '',
|
||||||
|
phone: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
axios.get(baseURL+"/market/"+props.marketId)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
//console.log(data)
|
||||||
|
setMarket(data);
|
||||||
|
})
|
||||||
|
|
||||||
|
axios.get(baseURL+"/markets/")
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res.data)
|
||||||
|
setMarkets(res.data);
|
||||||
|
})
|
||||||
|
|
||||||
|
},[])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const handleExchange = () => {
|
||||||
|
setExchangeMarket({ ...exchangeMarket, oldMarket: market });
|
||||||
|
setOpenExchangeDialog(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleExchangeClose = () => {
|
||||||
|
setOpenExchangeDialog(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleMarketExchange = async () => {
|
||||||
|
console.log(exchangeMarket)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const receivedData = await axios.post(baseURL+"/exchangePurchaseMarket/"+props.purchaseId, {
|
||||||
|
data: exchangeMarket,
|
||||||
|
})
|
||||||
|
|
||||||
|
//const newData = tableData.map((row) => (row.id === exchangeArticle.oldRow.id ? receivedData.data : row));
|
||||||
|
setMarket(exchangeMarket.newMarket);
|
||||||
|
//const receivedData = null
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
|
||||||
|
|
||||||
|
setOpenExchangeDialog(false);
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCloseSnackbar = () => setSnackbar(null);
|
||||||
|
|
||||||
|
const renderExchangeDialog = () => {
|
||||||
|
return (
|
||||||
|
<Dialog open={openExchangeDialog} onClose={handleExchangeClose}>
|
||||||
|
<DialogTitle>Austausch eines Marketes gegen einen vorhandenen Markt</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={5} alignItems="stretch" style={{ display: "flex" }}>
|
||||||
|
Markt austauschen gegen:
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={7} alignItems="stretch" style={{ display: "flex" }}>
|
||||||
|
<Select
|
||||||
|
fullWidth
|
||||||
|
id="exchangeArticle"
|
||||||
|
value={exchangeMarket.newMarket.name}
|
||||||
|
label="Market"
|
||||||
|
onChange={(e,t) => {setExchangeMarket({...exchangeMarket, newMarket: markets.filter((element) => element.id === Number(t.key.replace('.$','')))[0] });}}
|
||||||
|
>
|
||||||
|
{markets.map((market) => (
|
||||||
|
<MenuItem
|
||||||
|
key={market.id}
|
||||||
|
value={market.name}
|
||||||
|
//style={getStyles(name, personName, theme)}
|
||||||
|
>
|
||||||
|
{market.name+', '+market.street+' '+market.street_number+', '+market.city}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Grid>
|
||||||
|
<FormControlLabel control={
|
||||||
|
<Checkbox
|
||||||
|
label='delete?'
|
||||||
|
checked={exchangeMarket.deleteOld}
|
||||||
|
onChange={(e) => {setExchangeMarket({ ...exchangeMarket, deleteOld: !exchangeMarket.deleteOld });}}
|
||||||
|
inputProps={{ 'aria-label': 'controlled' }}
|
||||||
|
/>
|
||||||
|
} label="Ursprünglichen Artikel löschen?"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={handleExchangeClose}>Abbrechen</Button>
|
||||||
|
<Button onClick={handleMarketExchange}>Änderung speichern</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return(
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
{renderExchangeDialog()}
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<TextField
|
||||||
|
autoFocus
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="name"
|
||||||
|
value={market.name}
|
||||||
|
/*
|
||||||
|
onChange={(event) =>
|
||||||
|
setMarket({
|
||||||
|
...market,
|
||||||
|
name: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
label="Name"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={9}>
|
||||||
|
<TextField
|
||||||
|
margin="dense"
|
||||||
|
fullWidth
|
||||||
|
id="street"
|
||||||
|
value={market.street}
|
||||||
|
/*
|
||||||
|
onChange={(event) =>
|
||||||
|
setMarket({
|
||||||
|
...market,
|
||||||
|
street: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
label="Straße"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={2}>
|
||||||
|
<TextField
|
||||||
|
margin="dense"
|
||||||
|
id="streetnum"
|
||||||
|
fullWidth
|
||||||
|
value={market.street_number}
|
||||||
|
/*
|
||||||
|
onChange={(event) =>
|
||||||
|
setMarket({
|
||||||
|
...market,
|
||||||
|
streetNum: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
label="Nr."
|
||||||
|
type="number"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={4}>
|
||||||
|
<TextField
|
||||||
|
margin="dense"
|
||||||
|
id="zip"
|
||||||
|
fullWidth
|
||||||
|
value={market.zip_code}
|
||||||
|
/*
|
||||||
|
onChange={(event) =>
|
||||||
|
setMarket({
|
||||||
|
...market,
|
||||||
|
zip: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
label="PLZ"
|
||||||
|
type="number"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={8}>
|
||||||
|
<TextField
|
||||||
|
margin="dense"
|
||||||
|
id="city"
|
||||||
|
fullWidth
|
||||||
|
value={market.city}
|
||||||
|
/*
|
||||||
|
onChange={(event) =>
|
||||||
|
setMarket({
|
||||||
|
...market,
|
||||||
|
city: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
label="Stadt"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<TextField
|
||||||
|
margin="dense"
|
||||||
|
id="phone"
|
||||||
|
fullWidth
|
||||||
|
value={market.phone}
|
||||||
|
/*
|
||||||
|
onChange={(event) =>
|
||||||
|
setMarket({
|
||||||
|
...market,
|
||||||
|
tel: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
label="Telefon"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={3}>
|
||||||
|
<Button onClick={handleExchange}>Markt austauschen</Button>
|
||||||
|
</Grid>
|
||||||
|
{!!snackbar && (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
|
onClose={handleCloseSnackbar}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
>
|
||||||
|
<Alert {...snackbar} onClose={handleCloseSnackbar} />
|
||||||
|
</Snackbar>
|
||||||
|
)}
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MarketDetail
|
||||||
|
|
||||||
90
reactFrontend/src/components/Navbar.jsx
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
import { AppBar, Toolbar, styled, Typography, IconButton, alpha, InputBase } from '@mui/material'
|
||||||
|
import MenuIcon from '@mui/icons-material/Menu';
|
||||||
|
import SearchIcon from '@mui/icons-material/Search';
|
||||||
|
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
const StyledToolbar = styled(Toolbar)({
|
||||||
|
display:"flex",
|
||||||
|
justifyContent:"space-between",
|
||||||
|
})
|
||||||
|
|
||||||
|
const Search = styled('div')(({ theme }) => ({
|
||||||
|
position: 'relative',
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
backgroundColor: alpha(theme.palette.common.white, 0.15),
|
||||||
|
'&:hover': {
|
||||||
|
backgroundColor: alpha(theme.palette.common.white, 0.25),
|
||||||
|
},
|
||||||
|
marginLeft: 0,
|
||||||
|
width: '100%',
|
||||||
|
[theme.breakpoints.up('sm')]: {
|
||||||
|
marginLeft: theme.spacing(1),
|
||||||
|
width: 'auto',
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const SearchIconWrapper = styled('div')(({ theme }) => ({
|
||||||
|
padding: theme.spacing(0, 2),
|
||||||
|
height: '100%',
|
||||||
|
position: 'absolute',
|
||||||
|
pointerEvents: 'none',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledInputBase = styled(InputBase)(({ theme }) => ({
|
||||||
|
color: 'inherit',
|
||||||
|
'& .MuiInputBase-input': {
|
||||||
|
padding: theme.spacing(1, 1, 1, 0),
|
||||||
|
// vertical padding + font size from searchIcon
|
||||||
|
paddingLeft: `calc(1em + ${theme.spacing(4)})`,
|
||||||
|
transition: theme.transitions.create('width'),
|
||||||
|
width: '100%',
|
||||||
|
[theme.breakpoints.up('sm')]: {
|
||||||
|
width: '12ch',
|
||||||
|
'&:focus': {
|
||||||
|
width: '20ch',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const Navbar = () => {
|
||||||
|
return (
|
||||||
|
<AppBar
|
||||||
|
position="sticky"
|
||||||
|
>
|
||||||
|
<StyledToolbar>
|
||||||
|
<IconButton
|
||||||
|
size="large"
|
||||||
|
edge="start"
|
||||||
|
color="inherit"
|
||||||
|
aria-label="open drawer"
|
||||||
|
sx={{ mr: 2 }}
|
||||||
|
>
|
||||||
|
<MenuIcon />
|
||||||
|
</IconButton>
|
||||||
|
<Typography
|
||||||
|
variant="h6"
|
||||||
|
sx={{ display: {xs: "none", sm: "block"} }}
|
||||||
|
>
|
||||||
|
Kassenzettel
|
||||||
|
</Typography>
|
||||||
|
<Search>
|
||||||
|
<SearchIconWrapper>
|
||||||
|
<SearchIcon />
|
||||||
|
</SearchIconWrapper>
|
||||||
|
<StyledInputBase
|
||||||
|
placeholder="Search…"
|
||||||
|
inputProps={{ 'aria-label': 'search' }}
|
||||||
|
/>
|
||||||
|
</Search>
|
||||||
|
</StyledToolbar>
|
||||||
|
</AppBar>
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Navbar
|
||||||
231
reactFrontend/src/components/NutriDataGrid.component.js
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
//import { useNavigate, useLocation } from 'react-router-dom';
|
||||||
|
import { Button } from '@mui/material'
|
||||||
|
|
||||||
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
|
import DeleteIcon from '@mui/icons-material/DeleteOutlined';
|
||||||
|
|
||||||
|
import { DataGrid, GridToolbarContainer, GridActionsCellItem } from '@mui/x-data-grid';
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
//const apiURL = "/article/packaging"
|
||||||
|
|
||||||
|
/*
|
||||||
|
- Crashes if deleting an entry
|
||||||
|
*/
|
||||||
|
|
||||||
|
function EditToolbar(props) {
|
||||||
|
const { setTableData, article } = props;
|
||||||
|
|
||||||
|
const handleClick = async () => {
|
||||||
|
|
||||||
|
const newValue = {id: Math.floor(Math.random() * 1000)+10, value: 0, isEstimated: false, unit: 'g'}
|
||||||
|
|
||||||
|
setTableData((oldRows) => [...oldRows, newValue]);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<GridToolbarContainer>
|
||||||
|
<Button color="primary" startIcon={<AddIcon />} onClick={handleClick}>
|
||||||
|
Neuer Eintrag
|
||||||
|
</Button>
|
||||||
|
</GridToolbarContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditToolbar.propTypes = {
|
||||||
|
setTableData: PropTypes.func.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
const NutriDataGrid = (props) => {
|
||||||
|
const { article } = props;
|
||||||
|
|
||||||
|
const [tableData, setTableData] = useState([{id: -1, type: '', serving: 0, unit: 'g'}]);
|
||||||
|
const [options, setOptions] = useState([{id: -1, name: ''}]);
|
||||||
|
|
||||||
|
const [snackbar, setSnackbar] = useState(null);
|
||||||
|
|
||||||
|
const units = ['kg','g','mg','µg','l','ml','St','kJ','kcal'];
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
field: 'isEstimated',
|
||||||
|
headerName: 'Schätzung?',
|
||||||
|
width: 100,
|
||||||
|
editable: true,
|
||||||
|
type: 'boolean',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'nutrient',
|
||||||
|
headerName: 'Nährwert',
|
||||||
|
width:150,
|
||||||
|
type: 'singleSelect',
|
||||||
|
//valueOptions: () => {return options.map(x => x.name)},
|
||||||
|
valueOptions: options,
|
||||||
|
getOptionValue: (value) => value.id,
|
||||||
|
getOptionLabel: (value) => value.name,
|
||||||
|
editable: true,
|
||||||
|
flex: 1,
|
||||||
|
valueGetter: (params) => {try {return params.row.nutrient.id;} catch {return '';} },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'value',
|
||||||
|
headerName: '100g/100ml',
|
||||||
|
editable: true,
|
||||||
|
type: 'number',
|
||||||
|
//valueGetter: (params) => { return params.row.data.serving },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'unit',
|
||||||
|
headerName: 'Einheit',
|
||||||
|
type: 'singleSelect',
|
||||||
|
valueOptions: units,
|
||||||
|
editable: true,
|
||||||
|
//valueGetter: (params) => { return params.row.data.unit },
|
||||||
|
},
|
||||||
|
/*
|
||||||
|
{field: 'portion', headerName: 'Portion'},
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
field: 'actions',
|
||||||
|
type: 'actions',
|
||||||
|
headerName: 'Aktionen',
|
||||||
|
width: 100,
|
||||||
|
cellClassName: 'actions',
|
||||||
|
getActions: ({ id }) => {
|
||||||
|
return [
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<DeleteIcon />}
|
||||||
|
label="Delete"
|
||||||
|
onClick={(e) => handleDeleteClick(id,e)}
|
||||||
|
color="inherit"
|
||||||
|
/>,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const handleCloseSnackbar = () => setSnackbar(null);
|
||||||
|
|
||||||
|
//Anscheinend ist es notwendig das event e zu übergeben, ansonsten passieren komische Dinge (kein async, multiple trigger beim rendern etc)
|
||||||
|
const handleDeleteClick = async (id,e) => {
|
||||||
|
const newData = tableData.filter((row) => row.id !== id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const receivedData = await axios.delete(baseURL+"/article/nutritionalValues/"+article.pk, {
|
||||||
|
data: id,
|
||||||
|
})
|
||||||
|
setSnackbar({ children: 'Nährwert erfolgreich gelöscht', severity: 'success' });
|
||||||
|
setTableData(newData);
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const processRowUpdate = React.useCallback( async (newRow, oldRow) => {
|
||||||
|
console.log(newRow)
|
||||||
|
|
||||||
|
var nutrient;
|
||||||
|
if (newRow.nutrient === undefined) {
|
||||||
|
return newRow;
|
||||||
|
}
|
||||||
|
else if (typeof newRow.nutrient === 'number') {
|
||||||
|
nutrient = options.find(x => x.id === newRow.nutrient);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nutrient = newRow.nutrient;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedRow = {id: newRow.id, article_id: article.pk, nutrient: nutrient, value: newRow.value, unit: newRow.unit, isEstimated: newRow.isEstimated, isNew: false};
|
||||||
|
const newData = tableData.map((row) => (row.id === newRow.id ? updatedRow : row));
|
||||||
|
//console.log(newData)
|
||||||
|
try {
|
||||||
|
//const newCompleteData = {article: article.pk, data: newData, id: id};
|
||||||
|
//console.log(newCompleteData)
|
||||||
|
const response = await axios.put(baseURL+"/article/nutritionalValues/"+article.pk, {
|
||||||
|
nutriData: updatedRow
|
||||||
|
});
|
||||||
|
|
||||||
|
//console.log(response);
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
|
||||||
|
setTableData(newData);
|
||||||
|
//onChange(newData);
|
||||||
|
return updatedRow;
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
return oldRow;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
//const handleProcessRowUpdateError = React.useCallback((error) => {
|
||||||
|
// setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
//}, []);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() =>{
|
||||||
|
async function fetchOptions() {
|
||||||
|
const ans = await axios.get(baseURL+"/article/nutrients/");
|
||||||
|
setOptions(ans.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchData() {
|
||||||
|
const values = await axios.get(baseURL+"/article/nutritionalValues/"+article.pk);
|
||||||
|
setTableData(values.data);
|
||||||
|
}
|
||||||
|
fetchOptions();
|
||||||
|
fetchData();
|
||||||
|
|
||||||
|
},[article])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ height: 570, width: '100%' }}>
|
||||||
|
<DataGrid
|
||||||
|
rows={tableData}
|
||||||
|
columns={columns}
|
||||||
|
pageSize={10}
|
||||||
|
editMode="cell"
|
||||||
|
//getRowId={(row) => row.internalId}
|
||||||
|
processRowUpdate={processRowUpdate}
|
||||||
|
//onProcessRowUpdateError={handleProcessRowUpdateError}
|
||||||
|
//isCellEditable={(params) => {console.log(params);return !permanentOptions.includes(params.field) }}
|
||||||
|
experimentalFeatures={{ newEditingApi: true }}
|
||||||
|
components={{
|
||||||
|
Toolbar: EditToolbar,
|
||||||
|
}}
|
||||||
|
componentsProps={{
|
||||||
|
toolbar: { setTableData, article },
|
||||||
|
}}
|
||||||
|
initialState={{
|
||||||
|
sorting: {
|
||||||
|
sortModel: [{ field: 'id', sort: 'desc' }],
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
|
||||||
|
/>
|
||||||
|
{!!snackbar && (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
|
onClose={handleCloseSnackbar}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
>
|
||||||
|
<Alert {...snackbar} onClose={handleCloseSnackbar} />
|
||||||
|
</Snackbar>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NutriDataGrid
|
||||||
240
reactFrontend/src/components/PackagingDataGrid.component.js
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
//import { useNavigate, useLocation } from 'react-router-dom';
|
||||||
|
import { Button, Autocomplete, TextField } from '@mui/material'
|
||||||
|
|
||||||
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
|
import EditIcon from '@mui/icons-material/Edit';
|
||||||
|
import DeleteIcon from '@mui/icons-material/DeleteOutlined';
|
||||||
|
import SaveIcon from '@mui/icons-material/Save';
|
||||||
|
import CancelIcon from '@mui/icons-material/Close';
|
||||||
|
|
||||||
|
import { DataGrid, GridRowModes, GridToolbarContainer, GridActionsCellItem } from '@mui/x-data-grid';
|
||||||
|
|
||||||
|
import ListFieldApi from "./ListFieldApi.component"
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
const apiURL = "/article/packaging"
|
||||||
|
|
||||||
|
|
||||||
|
const makeId = () => {
|
||||||
|
let ID = "";
|
||||||
|
let characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
for ( var i = 0; i < 12; i++ ) {
|
||||||
|
ID += characters.charAt(Math.floor(Math.random() * 36));
|
||||||
|
}
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EditToolbar = (props) => {
|
||||||
|
const { onChange, setRowModesModel, setList } = props;
|
||||||
|
|
||||||
|
const [inputValue, setInputValue] = React.useState('')
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
const id = makeId();
|
||||||
|
onChange([{ id, packaging: '', weight: '', isNew: true }]);
|
||||||
|
setRowModesModel((oldModel) => ({
|
||||||
|
...oldModel,
|
||||||
|
[id]: { mode: GridRowModes.Edit, fieldToFocus: 'packaging' },
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handelMaterialChange = (event) => {
|
||||||
|
if (event == null){
|
||||||
|
setInputValue('')
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
setInputValue(event.name);
|
||||||
|
}
|
||||||
|
//axios.get(baseURL+apiURL)
|
||||||
|
// .then((res) => {
|
||||||
|
// const data = res.data;
|
||||||
|
// setList(data);
|
||||||
|
// //console.log(data)
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<GridToolbarContainer>
|
||||||
|
<Button color="primary" startIcon={<AddIcon />} onClick={handleClick}>
|
||||||
|
Eintrag hinzufügen
|
||||||
|
</Button>
|
||||||
|
<ListFieldApi
|
||||||
|
apiURL={apiURL}
|
||||||
|
titleName="Material hinzufügen"
|
||||||
|
addName="Material"
|
||||||
|
multiple={false}
|
||||||
|
value={inputValue}
|
||||||
|
onChange={handelMaterialChange}
|
||||||
|
sx={{ width: 300 }}
|
||||||
|
/>
|
||||||
|
</GridToolbarContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditToolbar.propTypes = {
|
||||||
|
setRowModesModel: PropTypes.func.isRequired,
|
||||||
|
onChange: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialRows = [
|
||||||
|
{
|
||||||
|
id: makeId(),
|
||||||
|
packaging: 'Pappe',
|
||||||
|
weight: 0,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const PackagingDataGrid = (props) => {
|
||||||
|
|
||||||
|
const { value, onChange, setArticle,...rest } = props;
|
||||||
|
const [rows, setRows] = React.useState([]);
|
||||||
|
const [rowModesModel, setRowModesModel] = React.useState({});
|
||||||
|
const [list, setList] = useState([]);
|
||||||
|
const [inputValue, setInputValue] = React.useState('')
|
||||||
|
|
||||||
|
const columnsPackaging = [
|
||||||
|
{
|
||||||
|
field: 'packaging',
|
||||||
|
headerName: 'Material',
|
||||||
|
width: 350,
|
||||||
|
type: 'singleSelect',
|
||||||
|
valueOptions: () => {return list.map(x => x.name)},
|
||||||
|
editable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'weight',
|
||||||
|
headerName: 'Gewicht in g',
|
||||||
|
type: 'number',
|
||||||
|
width:100,
|
||||||
|
editable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'actions',
|
||||||
|
type: 'actions',
|
||||||
|
headerName: 'Actions',
|
||||||
|
width: 150,
|
||||||
|
cellClassName: 'actions',
|
||||||
|
getActions: ({ id }) => {
|
||||||
|
const isInEditMode = rowModesModel[id]?.mode === GridRowModes.Edit;
|
||||||
|
|
||||||
|
if (isInEditMode) {
|
||||||
|
return [
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<SaveIcon />}
|
||||||
|
label="Save"
|
||||||
|
onClick={handleSaveClick(id)}
|
||||||
|
/>,
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<CancelIcon />}
|
||||||
|
label="Cancel"
|
||||||
|
className="textPrimary"
|
||||||
|
onClick={handleCancelClick(id)}
|
||||||
|
color="inherit"
|
||||||
|
/>,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<EditIcon />}
|
||||||
|
label="Edit"
|
||||||
|
className="textPrimary"
|
||||||
|
onClick={handleEditClick(id,rows)}
|
||||||
|
color="inherit"
|
||||||
|
/>,
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<DeleteIcon />}
|
||||||
|
label="Delete"
|
||||||
|
onClick={handleDeleteClick(id)}
|
||||||
|
color="inherit"
|
||||||
|
/>,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
//const handleRowEditStart = (params, event) => {
|
||||||
|
// event.defaultMuiPrevented = true;
|
||||||
|
//};
|
||||||
|
|
||||||
|
const handleRowEditStop = (params, event) => {
|
||||||
|
event.defaultMuiPrevented = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditClick = (id, rows) => () => {
|
||||||
|
console.log(rowModesModel)
|
||||||
|
setRowModesModel({ ...rowModesModel, [id]: { mode: GridRowModes.Edit } });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSaveClick = (id) => () => {
|
||||||
|
setRowModesModel({ ...rowModesModel, [id]: { mode: GridRowModes.View } });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteClick = (id) => () => {
|
||||||
|
setRows(rows.filter((row) => row.id !== id));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancelClick = (id) => () => {
|
||||||
|
setRowModesModel({
|
||||||
|
...rowModesModel,
|
||||||
|
[id]: { mode: GridRowModes.View, ignoreModifications: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
const editedRow = rows.find((row) => row.id === id);
|
||||||
|
if (editedRow.isNew) {
|
||||||
|
setRows(rows.filter((row) => row.id !== id));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const processRowUpdate = (newRow) => {
|
||||||
|
const updatedRow = { ...newRow, isNew: false };
|
||||||
|
console.log(newRow)
|
||||||
|
setRows(rows.map((row) => (row.id === newRow.id ? updatedRow : row)));
|
||||||
|
return updatedRow;
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
axios.get(baseURL+apiURL)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
setList(data);
|
||||||
|
//console.log(data)
|
||||||
|
})
|
||||||
|
|
||||||
|
},[])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DataGrid
|
||||||
|
rows={value}
|
||||||
|
columns={columnsPackaging}
|
||||||
|
pageSize={10}
|
||||||
|
editMode="row"
|
||||||
|
rowModesModel={rowModesModel}
|
||||||
|
//onRowEditStart={handleRowEditStart}
|
||||||
|
onRowEditStop={handleRowEditStop}
|
||||||
|
processRowUpdate={processRowUpdate}
|
||||||
|
components={{
|
||||||
|
Toolbar: EditToolbar,
|
||||||
|
}}
|
||||||
|
componentsProps={{
|
||||||
|
toolbar: { onChange, setRowModesModel, setList },
|
||||||
|
}}
|
||||||
|
experimentalFeatures={{ newEditingApi: true }}
|
||||||
|
//onRowEditStop={handleRowEditStop}
|
||||||
|
//checkboxSelection
|
||||||
|
//disableSelectionOnClick
|
||||||
|
//onCellClick={handleDataGridClick}
|
||||||
|
//onCellDoubleClick={handleDataGridDoubleClick}
|
||||||
|
/>
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PackagingDataGrid
|
||||||
207
reactFrontend/src/components/PackagingDataGrid2.component.js
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
//import { useNavigate, useLocation } from 'react-router-dom';
|
||||||
|
import { Button } from '@mui/material'
|
||||||
|
|
||||||
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
|
import DeleteIcon from '@mui/icons-material/DeleteOutlined';
|
||||||
|
|
||||||
|
import { DataGrid, GridToolbarContainer, GridActionsCellItem } from '@mui/x-data-grid';
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
const apiURL = "/article/packaging/"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function EditToolbar(props) {
|
||||||
|
const { setTableData, articleId } = props;
|
||||||
|
|
||||||
|
const handleClick = async () => {
|
||||||
|
|
||||||
|
const newValue = { packaging_id: {id: -1, name: 'Bitte auswählen'}, weight: 0, isNew: true, article_id: articleId };
|
||||||
|
const receivedData = await axios.post(baseURL+"/article/articlePackagings/"+articleId, {
|
||||||
|
newValue,
|
||||||
|
})
|
||||||
|
|
||||||
|
//console.log(receivedData)
|
||||||
|
const newRow = { id: receivedData.data.id, packaging_id: {id: -1, name: 'Bitte auswählen'}, weight: receivedData.data.weight, isNew: true, article_id: receivedData.data.article_id };
|
||||||
|
|
||||||
|
setTableData((oldRows) => [...oldRows, newRow]);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<GridToolbarContainer>
|
||||||
|
<Button color="primary" startIcon={<AddIcon />} onClick={handleClick}>
|
||||||
|
Neuer Eintrag
|
||||||
|
</Button>
|
||||||
|
</GridToolbarContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditToolbar.propTypes = {
|
||||||
|
setTableData: PropTypes.func.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
const PackagingDataGrid2 = (props) => {
|
||||||
|
const { articleId } = props;
|
||||||
|
|
||||||
|
const [list, setList] = useState([]);
|
||||||
|
const [tableData, setTableData] = useState([{id: -1, packaging_id: {id: -1, name: ''}, weight: -1, article_id: -1}]);
|
||||||
|
const [snackbar, setSnackbar] = useState(null);
|
||||||
|
|
||||||
|
const columnsPackaging = [
|
||||||
|
{
|
||||||
|
field: 'packaging_id',
|
||||||
|
headerName: 'Material',
|
||||||
|
flex: 1,
|
||||||
|
type: 'singleSelect',
|
||||||
|
valueOptions: () => {return list.map(x => x.name).sort()},
|
||||||
|
editable: true,
|
||||||
|
valueGetter: (params) => {try {return params.row.packaging_id.name;} catch {return '';} },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'weight',
|
||||||
|
headerName: 'Gewicht in g',
|
||||||
|
type: 'number',
|
||||||
|
width:100,
|
||||||
|
editable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'actions',
|
||||||
|
type: 'actions',
|
||||||
|
headerName: 'Aktionen',
|
||||||
|
width: 100,
|
||||||
|
cellClassName: 'actions',
|
||||||
|
getActions: ({ id }) => {
|
||||||
|
return [
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<DeleteIcon />}
|
||||||
|
label="Delete"
|
||||||
|
onClick={(e) => handleDeleteClick(id,e)}
|
||||||
|
color="inherit"
|
||||||
|
/>,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const findId = (idToLookFor) => {
|
||||||
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
if (list[i].name === idToLookFor) {
|
||||||
|
return(list[i].id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCloseSnackbar = () => setSnackbar(null);
|
||||||
|
|
||||||
|
//Anscheinend ist es notwendig das event e zu übergeben, ansonsten passieren komische Dinge (kein async, multiple trigger beim rendern etc)
|
||||||
|
const handleDeleteClick = async (id,e) => {
|
||||||
|
const newData = tableData.filter((row) => row.id !== id);
|
||||||
|
//console.log('Delete clicked')
|
||||||
|
//console.log(id)
|
||||||
|
//console.log(e)
|
||||||
|
try {
|
||||||
|
const receivedData = await axios.delete(baseURL+"/article/articlePackagings/"+articleId, {
|
||||||
|
data: id,
|
||||||
|
})
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
setTableData(newData);
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const processRowUpdate = React.useCallback( async (newRow, oldRow) => {
|
||||||
|
const id = findId(newRow.packaging_id);
|
||||||
|
const updatedRow = {'id': newRow.id, 'packaging_id':{'id': id, 'name': newRow.packaging_id}, 'weight': newRow.weight, 'isNew': false, 'article_id': articleId};
|
||||||
|
const newData = tableData.map((row) => (row.id === newRow.id ? updatedRow : row));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.put(baseURL+"/article/articlePackagings/"+articleId, {
|
||||||
|
updatedRow
|
||||||
|
});
|
||||||
|
|
||||||
|
//console.log(response);
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
|
||||||
|
setTableData(newData);
|
||||||
|
//onChange(newData);
|
||||||
|
return updatedRow;
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
return oldRow;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
//const handleProcessRowUpdateError = React.useCallback((error) => {
|
||||||
|
// setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
//}, []);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
axios.get(baseURL+apiURL)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
setList(data);
|
||||||
|
})
|
||||||
|
|
||||||
|
axios.get(baseURL+"/article/articlePackagings/"+articleId)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
//Add id for each element for displaying in Data Grid
|
||||||
|
//data.forEach((item, i) => {
|
||||||
|
// item.id = i + 1;
|
||||||
|
//});
|
||||||
|
|
||||||
|
setTableData(data);
|
||||||
|
//console.log("Fetching packaging data")
|
||||||
|
//console.log(data)
|
||||||
|
})
|
||||||
|
|
||||||
|
},[])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ height: 350, width: '100%' }}>
|
||||||
|
<DataGrid
|
||||||
|
rows={tableData}
|
||||||
|
columns={columnsPackaging}
|
||||||
|
pageSize={10}
|
||||||
|
editMode="row"
|
||||||
|
//getRowId={(row) => row.internalId}
|
||||||
|
processRowUpdate={processRowUpdate}
|
||||||
|
//onProcessRowUpdateError={handleProcessRowUpdateError}
|
||||||
|
experimentalFeatures={{ newEditingApi: true }}
|
||||||
|
components={{
|
||||||
|
Toolbar: EditToolbar,
|
||||||
|
}}
|
||||||
|
componentsProps={{
|
||||||
|
toolbar: { setTableData, articleId },
|
||||||
|
}}
|
||||||
|
|
||||||
|
/>
|
||||||
|
{!!snackbar && (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
|
onClose={handleCloseSnackbar}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
>
|
||||||
|
<Alert {...snackbar} onClose={handleCloseSnackbar} />
|
||||||
|
</Snackbar>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PackagingDataGrid2
|
||||||
999
reactFrontend/src/components/PurchaseDetails.component.js
Normal file
@ -0,0 +1,999 @@
|
|||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
|
import { useNavigate, useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { DataGrid, GridToolbarContainer, GridActionsCellItem, GridRowModes } from '@mui/x-data-grid';
|
||||||
|
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
import Grid from '@mui/material/Grid'
|
||||||
|
import Button from '@mui/material/Button'
|
||||||
|
import TextField from '@mui/material/TextField';
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
|
import Box from '@mui/material/Box';
|
||||||
|
import Dialog from '@mui/material/Dialog';
|
||||||
|
import DialogTitle from '@mui/material/DialogTitle';
|
||||||
|
import DialogContent from '@mui/material/DialogContent';
|
||||||
|
import DialogActions from '@mui/material/DialogActions';
|
||||||
|
import Select from '@mui/material/Select';
|
||||||
|
import MenuItem from '@mui/material/MenuItem';
|
||||||
|
import Checkbox from '@mui/material/Checkbox';
|
||||||
|
import InputAdornment from '@mui/material/InputAdornment';
|
||||||
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
||||||
|
import FormControl from '@mui/material/FormControl';
|
||||||
|
import InputLabel from '@mui/material/InputLabel';
|
||||||
|
import {Autocomplete, createFilterOptions} from '@mui/material'
|
||||||
|
|
||||||
|
import { grey } from '@mui/material/colors';
|
||||||
|
|
||||||
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
|
import DeleteIcon from '@mui/icons-material/DeleteOutlined';
|
||||||
|
import EditIcon from '@mui/icons-material/Edit';
|
||||||
|
import SaveIcon from '@mui/icons-material/Save';
|
||||||
|
|
||||||
|
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
|
||||||
|
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
||||||
|
import { DatePicker } from '@mui/x-date-pickers/DatePicker';
|
||||||
|
|
||||||
|
import MarketDetail from "./MarketDetail.component";
|
||||||
|
import ReceipeCanvas from "./Canvas.component"
|
||||||
|
import ListFieldApiwoArticle from "./ListFieldApiwoArticle.component"
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
const filter = createFilterOptions();
|
||||||
|
|
||||||
|
function EditToolbar(props) {
|
||||||
|
const { setArticles, setOpenNewEntryDialog } = props;
|
||||||
|
|
||||||
|
const handleClick = async () => {
|
||||||
|
console.log("Neuer Eintrag")
|
||||||
|
setOpenNewEntryDialog(true);
|
||||||
|
const retArticles = await axios.get(baseURL+"/articles/", {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Here we just add a "Neuer Artikel" object to the list of all available articles. If this is selected later on, we ask the backend for a real new object.
|
||||||
|
const answerWithNewArticelOption = retArticles.data.concat({pk:-1, name: 'Neuer Artikel', brand: null});
|
||||||
|
setArticles(answerWithNewArticelOption);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<GridToolbarContainer>
|
||||||
|
<Button color="primary" startIcon={<AddIcon />} onClick={handleClick}>
|
||||||
|
Neuer Eintrag
|
||||||
|
</Button>
|
||||||
|
</GridToolbarContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditToolbar.propTypes = {
|
||||||
|
setArticles: PropTypes.func.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
|
const PurchaseDetails = (props) => {
|
||||||
|
const location = useLocation();
|
||||||
|
//location.state != null ? console.log(location.state.id) : console.log("No data to show");
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const noButtonRef = React.useRef(null);
|
||||||
|
const drawRef = React.useRef({});
|
||||||
|
|
||||||
|
const [img, setImg] = useState(new Image());
|
||||||
|
const [tableData, setTableData] = useState([{id: 1, quantity: 0, article_id: {name: '', brand: {name: ''}}, price: 0, MwSt: 7, inSale: false, map: '', purchase_id: -1}]);
|
||||||
|
const [drawData, setDrawData] = useState([]);
|
||||||
|
const [snackbar, setSnackbar] = useState(null);
|
||||||
|
const [rowModesModel, setRowModesModel] = useState({});
|
||||||
|
const [purchaseArticleRowId, setPurchaseArticleRowId] = useState(null);
|
||||||
|
const [doubleClickAllowed, setDoubleClickAllowed] = useState(true);
|
||||||
|
const [promiseArguments, setPromiseArguments] = React.useState(null);
|
||||||
|
const [openMapDialog, setOpenMapDialog] = useState(false);
|
||||||
|
const [openExchangeDialog, setOpenExchangeDialog] = useState(false);
|
||||||
|
const [openNewEntryDialog, setOpenNewEntryDialog] = useState(false);
|
||||||
|
const [mapString, setMapString] = useState({receipeString: {id: -1, name: ""}, location_x: 0, location_y: 0, location_h: 0, location_w: 0, pk: -1, rowId: -1, purchase_id: -1, receipeString: ""});
|
||||||
|
const [rowMode, setRowMod] = useState('view');
|
||||||
|
const [stringData, setStringData] = useState([]);
|
||||||
|
|
||||||
|
const [paymentType, setPaymentType] = useState(location.state.payment_type);
|
||||||
|
const [totalPrice, setTotalPrice] = useState(location.state.total_price);
|
||||||
|
const [purchaseDate, setpurchaseDate] = useState(location.state.purchase_date);
|
||||||
|
|
||||||
|
const [newArticle,setNewArticle] = useState({id: 1, quantity: 0, article_id: {name: '', brand: {name: ''}}, price: 0, MwSt: 7, inSale: false, map: '', purchase_id: -1});
|
||||||
|
const [articles, setArticles] = useState([]);
|
||||||
|
const [exchangeArticle, setExchangeArticle] = useState({rowData: {}, newArticle: {}, deleteOld: false});
|
||||||
|
//const [purchaseArticleRowId, setPurchaseArticleRowId, clearPurchaseArticleRowId] = useStickyState()
|
||||||
|
|
||||||
|
const paymentTypes = ['','EC','Bar','Kreditkarte']
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
field: 'quantity',
|
||||||
|
headerName: '#',
|
||||||
|
width: 60,
|
||||||
|
type: 'number',
|
||||||
|
editable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
headerName: 'Artikel',
|
||||||
|
valueGetter: (params) => { const brandName = params.row.article_id.brand === null ? '' : params.row.article_id.brand.name; const articleName = params.row.article_id === null ? '' : params.row.article_id.name;
|
||||||
|
return brandName + ' ' + articleName },
|
||||||
|
width: 190,
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'price',
|
||||||
|
headerName: 'Preis',
|
||||||
|
width: 80,
|
||||||
|
type: 'number',
|
||||||
|
editable: true,
|
||||||
|
valueFormatter: (params) => {
|
||||||
|
if (params.value == null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
//const valueFormatted = Number(params.value * 100).toLocaleString();
|
||||||
|
return `${params.value} €`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
field: 'MwSt',
|
||||||
|
headerName: 'MwSt',
|
||||||
|
valueGetter: (params) => { return params.row.article_id.MwSt },
|
||||||
|
valueFormatter: (params) => {
|
||||||
|
if (params.value == null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
//const valueFormatted = Number(params.value * 100).toLocaleString();
|
||||||
|
return `${params.value} %`;
|
||||||
|
},
|
||||||
|
width: 55,
|
||||||
|
type: 'number',
|
||||||
|
editable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'inSale',
|
||||||
|
headerName: 'Sale',
|
||||||
|
type: 'boolean',
|
||||||
|
width: 55,
|
||||||
|
editable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'sum_price',
|
||||||
|
headerName: '∑ Preise',
|
||||||
|
width: 80,
|
||||||
|
type: 'number',
|
||||||
|
valueFormatter: (params) => {
|
||||||
|
if (params.value == null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
//const valueFormatted = Number(params.value * 100).toLocaleString();
|
||||||
|
return `${params.value.toFixed(2)} €`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'actions',
|
||||||
|
type: 'actions',
|
||||||
|
headerName: 'Aktionen',
|
||||||
|
width: 100,
|
||||||
|
cellClassName: 'actions',
|
||||||
|
|
||||||
|
getActions: ({ id }) => {
|
||||||
|
return [
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={(rowMode === 'edit' && purchaseArticleRowId === id) ? <SaveIcon /> : <EditIcon />}
|
||||||
|
label="Edit"
|
||||||
|
onClick={(e) => handleEditSaveClick(e,id)}
|
||||||
|
color="inherit"
|
||||||
|
/>,
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<DeleteIcon />}
|
||||||
|
label="Delete"
|
||||||
|
onClick={(e) => handleDeleteClick(id,e)}
|
||||||
|
color="inherit"
|
||||||
|
/>,
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<EditIcon />}
|
||||||
|
label="Kassenzettel-String bearbeiten"
|
||||||
|
onClick={(e) => handleEditMapClick(id,e)}
|
||||||
|
showInMenu
|
||||||
|
/>,
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<EditIcon />}
|
||||||
|
label="Artikel austauschen"
|
||||||
|
onClick={(e) => handleExchangeClick(id,e)}
|
||||||
|
showInMenu
|
||||||
|
/>,
|
||||||
|
<GridActionsCellItem
|
||||||
|
icon={<EditIcon />}
|
||||||
|
label="Bereich übernehmen"
|
||||||
|
onClick={(e) => handleSaveLocation(id,e)}
|
||||||
|
showInMenu
|
||||||
|
/>,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
const handleCloseSnackbar = () => setSnackbar(null);
|
||||||
|
|
||||||
|
|
||||||
|
const handleDataGridClick = (e) => {
|
||||||
|
if (purchaseArticleRowId !== e.row.id) {
|
||||||
|
setRowModesModel({ ...rowModesModel, [purchaseArticleRowId]: { mode: GridRowModes.View } });
|
||||||
|
setDoubleClickAllowed(true);
|
||||||
|
setRowMod('view')
|
||||||
|
}
|
||||||
|
|
||||||
|
setPurchaseArticleRowId( e.row.id );
|
||||||
|
//setDrawData(e.row.map)
|
||||||
|
|
||||||
|
drawRef.current.draw(e.row.map)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const handleDataGridDoubleClick = (e) => {
|
||||||
|
console.log("PurchaseDetail->DoubleClick")
|
||||||
|
console.log(e.row)
|
||||||
|
if (doubleClickAllowed) {
|
||||||
|
navigate('/ArticleDetails', {state:e.row});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleEditSaveClick = (e, id) => {
|
||||||
|
|
||||||
|
if (!purchaseArticleRowId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rowMode === 'edit') {
|
||||||
|
setRowModesModel({ ...rowModesModel, [id]: { mode: GridRowModes.View } });
|
||||||
|
setDoubleClickAllowed(true);
|
||||||
|
setRowMod('view')
|
||||||
|
} else {
|
||||||
|
setRowModesModel({ ...rowModesModel, [id]: { mode: GridRowModes.Edit } });
|
||||||
|
setDoubleClickAllowed(false);
|
||||||
|
setRowMod('edit')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//console.log("Edit")
|
||||||
|
};
|
||||||
|
|
||||||
|
const processRowUpdate = React.useCallback( async (newRow, oldRow) => {
|
||||||
|
const newArticle = { ...newRow.article_id, MwSt: newRow.MwSt };
|
||||||
|
const updatedRow = {id: newRow.id, MSt: newRow.MwSt, article_id: newArticle, inSale: newRow.inSale,
|
||||||
|
map: newRow.map, net_weight: newRow.net_weight, price: newRow.price,
|
||||||
|
quantity: newRow.quantity, sum_price: newRow.quantity*newRow.price
|
||||||
|
};
|
||||||
|
|
||||||
|
const newData = tableData.map((row) => (row.id === updatedRow.id ? updatedRow : row));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.put(baseURL+"/purchase/article/"+newRow.id, {
|
||||||
|
newRow: updatedRow
|
||||||
|
});
|
||||||
|
|
||||||
|
//console.log(response);
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
|
||||||
|
setTableData(newData);
|
||||||
|
updateTotalPrice(newData);
|
||||||
|
//onChange(newData);
|
||||||
|
return updatedRow;
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
return oldRow;
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleDeleteClick = async (id,e) => {
|
||||||
|
console.log("Delete: "+id)
|
||||||
|
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
const receivedData = await axios.delete(baseURL+"/purchase/article/"+id, {
|
||||||
|
data: id,
|
||||||
|
})
|
||||||
|
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
setTableData(newData);
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
}*/
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
setPromiseArguments({ resolve, reject, id });
|
||||||
|
resolve(); // Nothing was changed
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditMapClick = (id, e) => {
|
||||||
|
const currentRow = tableData.filter((row) => row.id === id)[0];
|
||||||
|
setMapString({...currentRow.map,rowId: id});
|
||||||
|
setOpenMapDialog(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSaveLocation = async (id, e) => {
|
||||||
|
var currentRow = tableData.filter((row) => row.id === id)[0];
|
||||||
|
|
||||||
|
const locationData = {pk: currentRow.map.pk,
|
||||||
|
receipeString: currentRow.map.receipeString,
|
||||||
|
location_x: drawData.location_x,
|
||||||
|
location_y: drawData.location_y,
|
||||||
|
location_h: drawData.location_h,
|
||||||
|
location_w: drawData.location_w
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const receivedData = await axios.put(baseURL+"/article/maps/"+locationData.pk, {
|
||||||
|
data: locationData,
|
||||||
|
})
|
||||||
|
|
||||||
|
currentRow.map = locationData;
|
||||||
|
const newData = tableData.map((row) => (row.id === currentRow.id ? currentRow : row));
|
||||||
|
setTableData(newData);
|
||||||
|
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleMapClose = () => {
|
||||||
|
setOpenMapDialog(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleExchangeClick = (id, e) => {
|
||||||
|
const currentRow = tableData.filter((row) => row.id === id)[0];
|
||||||
|
console.log(currentRow);
|
||||||
|
setExchangeArticle({ ...exchangeArticle, oldRow: currentRow });
|
||||||
|
setOpenExchangeDialog(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleExchangeClose = () => {
|
||||||
|
setOpenExchangeDialog(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleNewEntryClose = async () => {
|
||||||
|
setOpenNewEntryDialog(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleMapEdit = async () => {
|
||||||
|
try {
|
||||||
|
//const newMap = { ...mapString, receipeString: mapString };
|
||||||
|
console.log(mapString)
|
||||||
|
const receivedData = await axios.put(baseURL+"/article/maps/"+mapString.pk, {
|
||||||
|
data: mapString,
|
||||||
|
})
|
||||||
|
|
||||||
|
//const receivedData = null
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
|
||||||
|
var newRow = tableData.filter((row) => row.id === mapString.rowId)[0];
|
||||||
|
newRow.map = mapString;
|
||||||
|
const newData = tableData.map((row) => (row.id === mapString.rowId ? newRow : row));
|
||||||
|
console.log(newData)
|
||||||
|
setTableData(newData);
|
||||||
|
|
||||||
|
setOpenMapDialog(false);
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleArticleExchange = async () => {
|
||||||
|
console.log(exchangeArticle)
|
||||||
|
|
||||||
|
try {
|
||||||
|
//const newMap = { ...mapString, receipeString: mapString };
|
||||||
|
console.log(mapString)
|
||||||
|
const receivedData = await axios.post(baseURL+"/exchangePurchaseArticles/", {
|
||||||
|
data: exchangeArticle,
|
||||||
|
})
|
||||||
|
|
||||||
|
const newData = tableData.map((row) => (row.id === exchangeArticle.oldRow.id ? receivedData.data : row));
|
||||||
|
setTableData(newData);
|
||||||
|
//const receivedData = null
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
|
||||||
|
|
||||||
|
setOpenExchangeDialog(false);
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleNewEntryAdd = async () => {
|
||||||
|
console.log(newArticle);
|
||||||
|
if (newArticle.article_id.name === "Neuer Artikel") {
|
||||||
|
try {
|
||||||
|
const receivedData = await axios.post(baseURL+"/newPurchaseArticles/"+location.state.id+"/", {
|
||||||
|
data: newArticle,
|
||||||
|
})
|
||||||
|
console.log("Received new article:")
|
||||||
|
console.log(receivedData.data)
|
||||||
|
const newTableData = tableData.concat(receivedData.data);
|
||||||
|
console.log(newTableData)
|
||||||
|
setTableData(newTableData);
|
||||||
|
updateTotalPrice(newTableData);
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
setOpenNewEntryDialog(false);
|
||||||
|
|
||||||
|
setNewArticle({id: 1, quantity: 0, article_id: {name: '', brand: {name: ''}}, price: 0, MwSt: 7, inSale: false, map: '', purchase_id: -1})
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
const sendData = {...newArticle, article_id: newArticle.article_id}
|
||||||
|
const receivedData = await axios.post(baseURL+"/purchaseArticles/"+location.state.id+"/", {
|
||||||
|
data: sendData,
|
||||||
|
})
|
||||||
|
|
||||||
|
//console.log(receivedData.data)
|
||||||
|
const newTableData = tableData.concat(receivedData.data);
|
||||||
|
console.log(receivedData.data)
|
||||||
|
setTableData(newTableData);
|
||||||
|
updateTotalPrice(newTableData);
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
setOpenNewEntryDialog(false);
|
||||||
|
|
||||||
|
setNewArticle({id: 1, quantity: 0, article_id: {name: '', brand: {name: ''}}, price: 0, MwSt: 7, inSale: false, map: '', purchase_id: -1})
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleNewArticleChange = (value) => {
|
||||||
|
const selectedArticle = articles.filter((article) => article.pk === value.id )[0]
|
||||||
|
setNewArticle({ ...newArticle, article_id: selectedArticle })
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSavePrice = async () => {
|
||||||
|
console.log(location.state)
|
||||||
|
const newPurchaseData = { ...location.state, total_price: totalPrice, payment_type: paymentType, purchase_date: purchaseDate, edit_finished: true, receipeImage: location.state.receipeImage.pk};
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const receivedData = await axios.put(baseURL+"/purchase/"+newPurchaseData.id, {
|
||||||
|
data: newPurchaseData,
|
||||||
|
})
|
||||||
|
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
setPromiseArguments(null);
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
setPromiseArguments(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSaveDate = async (val) => {
|
||||||
|
console.log(val.format("YYYY-MM-DD"))
|
||||||
|
const newPurchaseData = { ...location.state, purchase_date: val.format("YYYY-MM-DD"), receipeImage: location.state.receipeImage.pk};
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const receivedData = await axios.put(baseURL+"/purchase/"+newPurchaseData.id, {
|
||||||
|
data: newPurchaseData,
|
||||||
|
})
|
||||||
|
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
setPromiseArguments(null);
|
||||||
|
setpurchaseDate(val.format("YYYY-MM-DD"));
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
setPromiseArguments(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNo = () => {
|
||||||
|
const { resolve } = promiseArguments;
|
||||||
|
resolve(); // Resolve with the old row to not update the internal state
|
||||||
|
setPromiseArguments(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
// If in delete dialog box yes is choosen, we will delete the article in the backend
|
||||||
|
const handleYes = async () => {
|
||||||
|
|
||||||
|
const { reject, resolve, id } = promiseArguments;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const receivedData = await axios.delete(baseURL+"/purchase/article/"+id, {
|
||||||
|
data: id,
|
||||||
|
})
|
||||||
|
|
||||||
|
const newData = tableData.filter((row) => row.id !== id);
|
||||||
|
setTableData(newData);
|
||||||
|
updateTotalPrice(newData);
|
||||||
|
setSnackbar({ children: 'Änderungen erfolgreich gespeichert', severity: 'success' });
|
||||||
|
resolve(receivedData);
|
||||||
|
setPromiseArguments(null);
|
||||||
|
} catch (error) {
|
||||||
|
setSnackbar({ children: error.message, severity: 'error' });
|
||||||
|
reject();
|
||||||
|
setPromiseArguments(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const handleEntered = () => {
|
||||||
|
// The `autoFocus` is not used because, if used, the same Enter that saves
|
||||||
|
// the cell triggers "No". Instead, we manually focus the "No" button once
|
||||||
|
// the dialog is fully open.
|
||||||
|
// noButtonRef.current?.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderExchangeDialog = () => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={openExchangeDialog} onClose={handleExchangeClose}>
|
||||||
|
<DialogTitle>Austausch eines Artikels gegen einen vorhandenen Artikel</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={5} alignItems="stretch" style={{ display: "flex" }}>
|
||||||
|
Artikel austauschen gegen:
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={7} alignItems="stretch" style={{ display: "flex" }}>
|
||||||
|
{/*
|
||||||
|
<Select
|
||||||
|
fullWidth
|
||||||
|
id="exchangeArticle"
|
||||||
|
value={exchangeArticle.newArticle.name}
|
||||||
|
label="Artikel"
|
||||||
|
onChange={(e,t) => {setExchangeArticle({ ...exchangeArticle, newArticle: articles.filter((element) => element.pk === Number(t.key.replace('.$','')))[0] });}}
|
||||||
|
>
|
||||||
|
{articles.map((article) => (
|
||||||
|
<MenuItem
|
||||||
|
key={article.pk}
|
||||||
|
value={article.name}
|
||||||
|
//style={getStyles(name, personName, theme)}
|
||||||
|
>
|
||||||
|
{(article.brand !== null ? article.brand.name : '')+' '+article.name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select> */}
|
||||||
|
<Autocomplete
|
||||||
|
multiple={false}
|
||||||
|
id="exchangeArticle"
|
||||||
|
fullWidth
|
||||||
|
options={articles.map((article) => (
|
||||||
|
{name: article.name, brand: article.brand !== null ? article.brand.name : '', id: article.pk}
|
||||||
|
)).sort((a, b) => {
|
||||||
|
const nameA = a.brand + ' ' +a.name.toUpperCase(); // ignore upper and lowercase
|
||||||
|
const nameB = b.brand + ' ' +b.name.toUpperCase(); // ignore upper and lowercase
|
||||||
|
if (nameA < nameB) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (nameA > nameB) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// names must be equal
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
groupBy={(option) => option.brand}
|
||||||
|
renderOption={(props, option) => (
|
||||||
|
<Box component="li" {...props} key={option.id}>
|
||||||
|
{option.brand + ' ' +option.name}
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
getOptionLabel={(option) => {
|
||||||
|
if (option.name === undefined){
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return option.brand + ' ' +option.name
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
variant="standard"
|
||||||
|
label='Marke + Artikel'
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
//onChange={(event, newValue) => {handleNewArticleChange(newValue)}}
|
||||||
|
onChange={(e,t) => {setExchangeArticle({ ...exchangeArticle, newArticle: articles.filter((element) => element.pk === t.id)[0] });}}
|
||||||
|
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<FormControlLabel control={
|
||||||
|
<Checkbox
|
||||||
|
label='Sale?'
|
||||||
|
checked={exchangeArticle.deleteOld}
|
||||||
|
onChange={(e) => {setExchangeArticle({ ...exchangeArticle, deleteOld: !exchangeArticle.deleteOld });}}
|
||||||
|
inputProps={{ 'aria-label': 'controlled' }}
|
||||||
|
/>
|
||||||
|
} label="Ursprünglichen Artikel löschen?"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={handleExchangeClose}>Abbrechen</Button>
|
||||||
|
<Button onClick={handleArticleExchange}>Änderung speichern</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const renderConfirmDialog = () => {
|
||||||
|
if (!promiseArguments) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//const { newRow, oldRow } = promiseArguments;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
maxWidth="xs"
|
||||||
|
TransitionProps={{ onEntered: handleEntered }}
|
||||||
|
open={!!promiseArguments}
|
||||||
|
>
|
||||||
|
<DialogTitle>Sind sie sicher?</DialogTitle>
|
||||||
|
<DialogContent dividers>
|
||||||
|
{`Ein klick auf 'Ja' wir die Daten löschen.`}
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button ref={noButtonRef} onClick={handleNo}>
|
||||||
|
Nein
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleYes}>Ja</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateTotalPrice = (val) => {
|
||||||
|
const sumWithInitial = val.reduce(
|
||||||
|
(accumulator, currentValue) => accumulator + currentValue.sum_price,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
setTotalPrice(sumWithInitial.toFixed(2));
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
|
||||||
|
var myImage = new Image();
|
||||||
|
myImage.src = baseURL+"/receipeImage/"+location.state.receipeImage.pk;
|
||||||
|
setImg(myImage)
|
||||||
|
drawRef.current.drawImage(myImage);
|
||||||
|
|
||||||
|
axios.get(baseURL+"/purchaseArticles/"+location.state.id)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
//console.log(tableData)
|
||||||
|
console.log(data)
|
||||||
|
setTableData(data);
|
||||||
|
|
||||||
|
updateTotalPrice(data);
|
||||||
|
})
|
||||||
|
|
||||||
|
axios.get(baseURL+"/articles/")
|
||||||
|
.then((res) => {
|
||||||
|
setArticles(res.data);
|
||||||
|
})
|
||||||
|
|
||||||
|
axios.get(baseURL+"/article/mapStrings/")
|
||||||
|
.then((res) => {
|
||||||
|
setStringData(res.data);
|
||||||
|
})
|
||||||
|
|
||||||
|
},[])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return(
|
||||||
|
<div style={{ height: 800, width: '100%' }}>
|
||||||
|
<h1> Details zum Einkauf vom {purchaseDate} </h1>
|
||||||
|
|
||||||
|
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
||||||
|
<DatePicker
|
||||||
|
value={dayjs(purchaseDate)}
|
||||||
|
onChange={handleSaveDate}
|
||||||
|
/>
|
||||||
|
</LocalizationProvider>
|
||||||
|
|
||||||
|
<Box sx={{ borderRadius: '4px', p: 2, border: '1px solid', borderColor: grey[300] }}>
|
||||||
|
<MarketDetail
|
||||||
|
marketId={location.state.market.id}
|
||||||
|
purchaseId={location.state.id}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={8}>
|
||||||
|
<div style={{ display: 'flex', height: '1200px' }}>
|
||||||
|
<div style={{ flexGrow: 1 }}>
|
||||||
|
{renderConfirmDialog()}
|
||||||
|
{renderExchangeDialog()}
|
||||||
|
{/*Map String Dialog*/}
|
||||||
|
<Dialog open={openMapDialog} onClose={handleMapClose}>
|
||||||
|
<DialogTitle>Bearbeiten des OCR-Artikel Strings</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
{/*
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="mapStringField"
|
||||||
|
//defaultValue={name != null ? name : ""}
|
||||||
|
value={mapString.receipeString.receipeString}
|
||||||
|
onChange={(e) => setMapString({ ...mapString, receipeString: {...mapString.receipeString, receipeString: e.target.value} })}
|
||||||
|
error={(mapString.length === 0)}
|
||||||
|
label="OCR Mapping String"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
*/}
|
||||||
|
<ListFieldApiwoArticle
|
||||||
|
apiURL="/article/mapStrings/"
|
||||||
|
titleName="String"
|
||||||
|
addName="String hinzufügen"
|
||||||
|
multiple={false}
|
||||||
|
value={mapString.receipeString}
|
||||||
|
onChange={(e) => {setMapString({ ...mapString, receipeString: e })}}
|
||||||
|
sx={{width:'400px'}}
|
||||||
|
addNew={true}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={handleMapClose}>Abbrechen</Button>
|
||||||
|
<Button onClick={handleMapEdit}>Änderung speichern</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
<Dialog open={openNewEntryDialog} onClose={handleNewEntryClose}>
|
||||||
|
<DialogTitle>Neuer Eintrag hinzufügen</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={1}>
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="newQuantityField"
|
||||||
|
//defaultValue={name != null ? name : ""}
|
||||||
|
value={newArticle.quantity}
|
||||||
|
onChange={(e) => setNewArticle({ ...newArticle, quantity: e.target.value })}
|
||||||
|
error={(newArticle.quantity === 0)}
|
||||||
|
label="#"
|
||||||
|
type="number"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={5}>
|
||||||
|
<Autocomplete
|
||||||
|
multiple={false}
|
||||||
|
id="tags-standard"
|
||||||
|
fullWidth
|
||||||
|
options={articles.map((article) => (
|
||||||
|
{name: article.name, brand: article.brand !== null ? article.brand.name : '', id: article.pk}
|
||||||
|
)).sort((a, b) => {
|
||||||
|
const nameA = a.brand + ' ' +a.name.toUpperCase(); // ignore upper and lowercase
|
||||||
|
const nameB = b.brand + ' ' +b.name.toUpperCase(); // ignore upper and lowercase
|
||||||
|
if (nameA < nameB) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (nameA > nameB) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// names must be equal
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
groupBy={(option) => option.brand}
|
||||||
|
renderOption={(props, option) => (
|
||||||
|
<Box component="li" {...props} key={option.id}>
|
||||||
|
{option.brand + ' ' +option.name}
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
getOptionLabel={(option) => {
|
||||||
|
if (option.name === undefined){
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return option.brand + ' ' +option.name
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
variant="standard"
|
||||||
|
label='Marke + Artikel'
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
onChange={(event, newValue) => {handleNewArticleChange(newValue)}}
|
||||||
|
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={2}>
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="newPriceField"
|
||||||
|
//defaultValue={name != null ? name : ""}
|
||||||
|
value={newArticle.price}
|
||||||
|
onChange={(e) => setNewArticle({ ...newArticle, price: e.target.value })}
|
||||||
|
error={(newArticle.price === 0)}
|
||||||
|
label="Preis"
|
||||||
|
type="number"
|
||||||
|
variant="standard"
|
||||||
|
InputProps={{
|
||||||
|
endAdornment: <InputAdornment position="end">€</InputAdornment>
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={2}>
|
||||||
|
<TextField
|
||||||
|
width='10px'
|
||||||
|
margin="dense"
|
||||||
|
id="newMwSTField"
|
||||||
|
//defaultValue={name != null ? name : ""}
|
||||||
|
value={newArticle.MwSt}
|
||||||
|
onChange={(e) => setNewArticle({ ...newArticle, MwSt: e.target.value })}
|
||||||
|
label="MwSt"
|
||||||
|
type="number"
|
||||||
|
variant="standard"
|
||||||
|
InputProps={{
|
||||||
|
endAdornment: <InputAdornment position="end">%</InputAdornment>
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={2}>
|
||||||
|
<FormControlLabel control={
|
||||||
|
<Checkbox
|
||||||
|
label='Sale?'
|
||||||
|
checked={newArticle.inSale}
|
||||||
|
onChange={(e) => setNewArticle({ ...newArticle, inSale: !newArticle.inSale })}
|
||||||
|
inputProps={{ 'aria-label': 'controlled' }}
|
||||||
|
/>
|
||||||
|
} label="Sale?" />
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={handleNewEntryClose}>Abbrechen</Button>
|
||||||
|
<Button onClick={handleNewEntryAdd}>Hinzufügen</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
<DataGrid
|
||||||
|
rows={tableData}
|
||||||
|
columns={columns}
|
||||||
|
editMode="row"
|
||||||
|
//pageSize={15}
|
||||||
|
onCellClick={handleDataGridClick}
|
||||||
|
onCellDoubleClick={handleDataGridDoubleClick}
|
||||||
|
//onCellKeyDown={handleCellKeyDown}
|
||||||
|
rowModesModel={rowModesModel}
|
||||||
|
onRowModesModelChange={(model) => setRowModesModel(model)}
|
||||||
|
processRowUpdate={processRowUpdate}
|
||||||
|
|
||||||
|
experimentalFeatures={{ newEditingApi: true }}
|
||||||
|
components={{
|
||||||
|
Toolbar: EditToolbar,
|
||||||
|
}}
|
||||||
|
componentsProps={{
|
||||||
|
toolbar: {
|
||||||
|
setArticles,
|
||||||
|
setOpenNewEntryDialog
|
||||||
|
},
|
||||||
|
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={4}>
|
||||||
|
<FormControl sx={{ m: 1, minWidth: 120 }}>
|
||||||
|
<InputLabel>Zahlungsart</InputLabel>
|
||||||
|
<Select
|
||||||
|
|
||||||
|
id="payment_type"
|
||||||
|
value={paymentType}
|
||||||
|
label="Zahlungsart"
|
||||||
|
onChange={(e) => {setPaymentType(e.target.value)}}
|
||||||
|
>
|
||||||
|
{paymentTypes.map((unit) => (
|
||||||
|
<MenuItem
|
||||||
|
key={unit}
|
||||||
|
value={unit}
|
||||||
|
//style={getStyles(name, personName, theme)}
|
||||||
|
>
|
||||||
|
{unit}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
|
||||||
|
</FormControl>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={6}>
|
||||||
|
<TextField
|
||||||
|
disabled
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="Gesamtpreis"
|
||||||
|
value={totalPrice}
|
||||||
|
onChange={(e) => setTotalPrice(e.target.value)}
|
||||||
|
label="Gesamtpreis"
|
||||||
|
type="number"
|
||||||
|
variant="standard"
|
||||||
|
/*
|
||||||
|
inputProps: object
|
||||||
|
Attributes applied to the input element.
|
||||||
|
|
||||||
|
InputProps: object
|
||||||
|
Props applied to the Input element. It will be a FilledInput, OutlinedInput or Input component depending on the variant prop value.
|
||||||
|
*/
|
||||||
|
InputProps={{ endAdornment: <InputAdornment position="end">€</InputAdornment> }}
|
||||||
|
inputProps={{ style: { textAlign: 'right' } }}
|
||||||
|
//onBlur={(e) => handleArticleChangeAPI(e,'EAN', e.target.value)}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={2} alignItems="stretch" style={{ display: "flex" }}>
|
||||||
|
<Button onClick={handleSavePrice}>
|
||||||
|
Preis übernehmen
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
{!!snackbar && (
|
||||||
|
<Snackbar
|
||||||
|
open
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
|
onClose={handleCloseSnackbar}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
>
|
||||||
|
<Alert {...snackbar} onClose={handleCloseSnackbar} />
|
||||||
|
</Snackbar>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={4}>
|
||||||
|
<ReceipeCanvas
|
||||||
|
setNewRect={setDrawData}
|
||||||
|
image={img}
|
||||||
|
myRef={drawRef}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PurchaseDetails
|
||||||
162
reactFrontend/src/components/PurchaseOverview.component.jsx
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
import { Button } from '@mui/material'
|
||||||
|
import {Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, TextField } from '@mui/material'
|
||||||
|
//import {Autocomplete, createFilterOptions } from '@mui/material';
|
||||||
|
import { DataGrid } from '@mui/x-data-grid';
|
||||||
|
|
||||||
|
import { Grid } from '@mui/material'
|
||||||
|
|
||||||
|
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
||||||
|
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
|
||||||
|
import { MobileDatePicker } from '@mui/x-date-pickers/MobileDatePicker';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
|
||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import SelectMarketField from "./selectMarket";
|
||||||
|
import UploadFiles from "./upload-files.component";
|
||||||
|
|
||||||
|
|
||||||
|
//const baseURL = "https://jsonplaceholder.typicode.com/comments";
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
|
||||||
|
const PurchaseOverview = (props) => {
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
field: 'edit_finished',
|
||||||
|
headerName: 'Fertig?',
|
||||||
|
type: 'boolean',
|
||||||
|
width: 100,
|
||||||
|
editable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'purchase_date',
|
||||||
|
headerName: 'Datum'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'market',
|
||||||
|
headerName: 'Markt',
|
||||||
|
valueGetter: (params) => { return params.row.market.name + ', ' + params.row.market.street + ' ' + params.row.market.street_number + ', ' + params.row.market.city},
|
||||||
|
width: 400,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'total_price',
|
||||||
|
headerName: 'Gesamtpreis',
|
||||||
|
flex: 1,
|
||||||
|
valueFormatter: (params) => {
|
||||||
|
if (params.value == null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
//const valueFormatted = Number(params.value * 100).toLocaleString();
|
||||||
|
return `${params.value} €`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
//{field: 'body', headerName: 'Body'}
|
||||||
|
]
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const [tableData, setTableData] = useState([]);
|
||||||
|
const [openAddDialog, setOpenAddDialog] = useState(false);
|
||||||
|
|
||||||
|
const [selectedDate, setSelectedDate] = React.useState(new Date());
|
||||||
|
|
||||||
|
const handleDataGridClick = (e) => {
|
||||||
|
//console.log(e.row)
|
||||||
|
navigate('/PurchaseDetails', {state:e.row});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClickAddDialogOpen = () => {
|
||||||
|
setOpenAddDialog(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setOpenAddDialog(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
axios.get(baseURL+"/purchase/")
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
console.log(data)
|
||||||
|
setTableData(data);
|
||||||
|
})
|
||||||
|
},[])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ height: 800, width: '100%' }}>
|
||||||
|
|
||||||
|
<Typography variant="h2" gutterBottom>
|
||||||
|
Übersicht über alle Einkäufe
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Button variant="contained"
|
||||||
|
onClick={handleClickAddDialogOpen}
|
||||||
|
>
|
||||||
|
Einkauf hinzufügen
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<Dialog open={openAddDialog} onClose={handleClose}>
|
||||||
|
<DialogTitle>Einkauf hinzufügen</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogContentText>
|
||||||
|
Füge einen neuen Einkauf hinzu. Entweder per Datum und Markt oder per Upload eines Kassenzettels.
|
||||||
|
</DialogContentText>
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={5}>
|
||||||
|
<LocalizationProvider dateAdapter={AdapterDateFns}>
|
||||||
|
<MobileDatePicker
|
||||||
|
label="Datum des Einkaufs"
|
||||||
|
value={selectedDate}
|
||||||
|
onChange={(newValue) => {
|
||||||
|
setSelectedDate(newValue);
|
||||||
|
}}
|
||||||
|
renderInput={(params) => <TextField {...params} />}
|
||||||
|
/>
|
||||||
|
</LocalizationProvider>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={6}>
|
||||||
|
<SelectMarketField/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<UploadFiles
|
||||||
|
apiURL='/purchase/post_receipe/'
|
||||||
|
fileName='receipe'
|
||||||
|
buttonText='Upload'
|
||||||
|
applyBinarize={false}
|
||||||
|
debug={true}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={handleClose}>Abbrechen</Button>
|
||||||
|
<Button onClick={handleClose}>Hinzufügen</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
<DataGrid
|
||||||
|
rows={tableData}
|
||||||
|
columns={columns}
|
||||||
|
pageSize={10}
|
||||||
|
//checkboxSelection
|
||||||
|
//disableSelectionOnClick
|
||||||
|
onCellClick={handleDataGridClick}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PurchaseOverview
|
||||||
53
reactFrontend/src/components/Sidebar.jsx
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { Box} from '@mui/material'
|
||||||
|
import React from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
import Button from '@mui/material/Button';
|
||||||
|
import Stack from '@mui/material/Stack';
|
||||||
|
|
||||||
|
const Sidebar = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const showArticles = (e) => {
|
||||||
|
console.log('Show articles');
|
||||||
|
navigate('/Articles', {});
|
||||||
|
};
|
||||||
|
|
||||||
|
const showPurchases = (e) => {
|
||||||
|
navigate('/', {});
|
||||||
|
};
|
||||||
|
|
||||||
|
const showAnalyses = (e) => {
|
||||||
|
console.log('Show analyses');
|
||||||
|
navigate('/Analyses', {});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box bgcolor="skyblue"
|
||||||
|
flex={1}
|
||||||
|
p={2}
|
||||||
|
sx={{ display: {xs: "none", sm: "block"} }}
|
||||||
|
>
|
||||||
|
<Stack spacing={2}>
|
||||||
|
<Button variant="text"
|
||||||
|
onClick={showPurchases}
|
||||||
|
>
|
||||||
|
Einkäufe
|
||||||
|
</Button>
|
||||||
|
<Button variant="text"
|
||||||
|
onClick={showArticles}
|
||||||
|
>
|
||||||
|
Artikel
|
||||||
|
</Button>
|
||||||
|
<Button variant="text"
|
||||||
|
onClick={showAnalyses}
|
||||||
|
>
|
||||||
|
Analysen
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Sidebar
|
||||||
58
reactFrontend/src/components/articleCard.component.jsx
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import {useState} from 'react'
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import Button from '@mui/material/Button';
|
||||||
|
//import Typography from '@mui/material/Typography';
|
||||||
|
import {Card, CardActions, CardContent, CardMedia } from '@mui/material'
|
||||||
|
//import {Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle} from '@mui/material'
|
||||||
|
//import FormGroup from '@mui/material/FormGroup';
|
||||||
|
//import FormControlLabel from '@mui/material/FormControlLabel';
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
const ArticleCard = (props) => {
|
||||||
|
const { article, navigate, onChange, filterBrand } = props;
|
||||||
|
|
||||||
|
const [openAddDialog, setOpenAddDialog] = useState(false);
|
||||||
|
const [error, setError] = useState(false);
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
navigate('/ArticleDetails', {state:{id: -1, article_id: article}});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card sx={{ height: 350, maxWidth: 345, position: "relative"}}>
|
||||||
|
<CardMedia
|
||||||
|
component="img"
|
||||||
|
height="200"
|
||||||
|
image={article.frontImage}
|
||||||
|
title="Bild"
|
||||||
|
sx={{ padding: "1em 1em 0 1em", objectFit: "contain" }}
|
||||||
|
/>
|
||||||
|
<CardContent>
|
||||||
|
|
||||||
|
<Button variant="text"
|
||||||
|
sx={{textTransform: "none"}}
|
||||||
|
onClick={filterBrand}
|
||||||
|
>
|
||||||
|
{article.brand === null ? "Unbekannte Marke:": article.brand.name+":"}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{article.name}
|
||||||
|
|
||||||
|
|
||||||
|
</CardContent>
|
||||||
|
|
||||||
|
<CardActions sx={{position: "absolute", bottom: 0,}}>
|
||||||
|
<Button size="small" onClick={handleClick}>
|
||||||
|
Öffnen
|
||||||
|
</Button>
|
||||||
|
</CardActions>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ArticleCard
|
||||||
110
reactFrontend/src/components/pictureCard.component.js
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import {useState} from 'react'
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import {Button, Stack, Input } from '@mui/material';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
import {Card, CardActions, CardContent, CardMedia } from '@mui/material'
|
||||||
|
import {Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle} from '@mui/material'
|
||||||
|
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
const PictureCard = (props) => {
|
||||||
|
const { type, article, pictureType, onChange } = props;
|
||||||
|
|
||||||
|
const [openAddDialog, setOpenAddDialog] = useState(false);
|
||||||
|
const [uploadFile, setUploadFile] = useState(null);
|
||||||
|
const [error, setError] = useState(false);
|
||||||
|
//const [image, setImage] = useState(eval("article."+pictureType));
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
setOpenAddDialog(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setOpenAddDialog(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUploadSelection = (e) => {
|
||||||
|
//console.log(e.target.files[0])
|
||||||
|
setUploadFile(e.target.files[0]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpload = (event) => {
|
||||||
|
event.preventDefault()
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("fileTitle", pictureType);
|
||||||
|
formData.append("uploadedFile", uploadFile);
|
||||||
|
axios.post(baseURL+'/article/post_articleImage/'+article.pk, formData, {
|
||||||
|
headers: {
|
||||||
|
'content-type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
setOpenAddDialog(false);
|
||||||
|
//console.log(response);
|
||||||
|
//setImage(eval("response.data."+pictureType))
|
||||||
|
onChange(response.data)
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
//console.log(error);
|
||||||
|
setError(true);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card sx={{ maxWidth: 345 }}>
|
||||||
|
<CardContent>
|
||||||
|
<Typography gutterBottom variant="h5" component="div">
|
||||||
|
{type}
|
||||||
|
</Typography>
|
||||||
|
</CardContent>
|
||||||
|
<CardMedia
|
||||||
|
component="img"
|
||||||
|
height="450"
|
||||||
|
image={eval("article."+pictureType)}
|
||||||
|
title="Bild"
|
||||||
|
sx={{ padding: "1em 1em 0 1em", objectFit: "contain" }}
|
||||||
|
/>
|
||||||
|
<CardActions>
|
||||||
|
<Button size="small" onClick={handleClick}>
|
||||||
|
{eval("article."+pictureType) === null ? "Bild hinzufügen" : "Neues Bild"}
|
||||||
|
</Button>
|
||||||
|
<Dialog open={openAddDialog} onClose={handleClose}>
|
||||||
|
<DialogTitle>Bild hinzufügen</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogContentText>
|
||||||
|
Bild auswählen und uploaden
|
||||||
|
</DialogContentText>
|
||||||
|
<Stack container spacing={1}>
|
||||||
|
<Input
|
||||||
|
accept="image/*"
|
||||||
|
id="contained-button-file"
|
||||||
|
multiple type="file"
|
||||||
|
onChange={handleUploadSelection}
|
||||||
|
//error={error.toString()}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Typography gutterBottom variant="subtitle1" component="div" color="red">
|
||||||
|
{error ? "Fehler beim uploaden des Files!" : ""}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
</Stack>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={handleClose}>
|
||||||
|
Abbrechen
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleUpload}>
|
||||||
|
Hinzufügen
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
</CardActions>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PictureCard
|
||||||
56
reactFrontend/src/components/prompts.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* These hooks re-implement the now removed useBlocker and usePrompt hooks in 'react-router-dom'.
|
||||||
|
* Thanks for the idea @piecyk https://github.com/remix-run/react-router/issues/8139#issuecomment-953816315
|
||||||
|
* Source: https://github.com/remix-run/react-router/commit/256cad70d3fd4500b1abcfea66f3ee622fb90874#diff-b60f1a2d4276b2a605c05e19816634111de2e8a4186fe9dd7de8e344b65ed4d3L344-L381
|
||||||
|
*/
|
||||||
|
import { useContext, useEffect, useCallback } from 'react';
|
||||||
|
import { UNSAFE_NavigationContext as NavigationContext } from 'react-router-dom';
|
||||||
|
/**
|
||||||
|
* Blocks all navigation attempts. This is useful for preventing the page from
|
||||||
|
* changing until some condition is met, like saving form data.
|
||||||
|
*
|
||||||
|
* @param blocker
|
||||||
|
* @param when
|
||||||
|
* @see https://reactrouter.com/api/useBlocker
|
||||||
|
*/
|
||||||
|
export function useBlocker( blocker, when = true ) {
|
||||||
|
const { navigator } = useContext( NavigationContext );
|
||||||
|
|
||||||
|
useEffect( () => {
|
||||||
|
if ( ! when ) return;
|
||||||
|
|
||||||
|
const unblock = navigator.block( ( tx ) => {
|
||||||
|
const autoUnblockingTx = {
|
||||||
|
...tx,
|
||||||
|
retry() {
|
||||||
|
// Automatically unblock the transition so it can play all the way
|
||||||
|
// through before retrying it. TODO: Figure out how to re-enable
|
||||||
|
// this block if the transition is cancelled for some reason.
|
||||||
|
unblock();
|
||||||
|
tx.retry();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
blocker( autoUnblockingTx );
|
||||||
|
} );
|
||||||
|
|
||||||
|
return unblock;
|
||||||
|
}, [ navigator, blocker, when ] );
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Prompts the user with an Alert before they leave the current screen.
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* @param when
|
||||||
|
*/
|
||||||
|
export default function usePrompt( message, when = true ) {
|
||||||
|
const blocker = useCallback(
|
||||||
|
( tx ) => {
|
||||||
|
// eslint-disable-next-line no-alert
|
||||||
|
if ( window.confirm( message ) ) tx.retry();
|
||||||
|
},
|
||||||
|
[ message ]
|
||||||
|
);
|
||||||
|
|
||||||
|
useBlocker( blocker, when );
|
||||||
|
}
|
||||||
292
reactFrontend/src/components/selectMarket.jsx
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
import {Autocomplete, createFilterOptions } from '@mui/material';
|
||||||
|
import { Button, Grid } from '@mui/material'
|
||||||
|
import {Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, TextField } from '@mui/material'
|
||||||
|
import {React, useState, useEffect, Fragment} from 'react'
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
const filter = createFilterOptions();
|
||||||
|
|
||||||
|
const SelectMarketField = () => {
|
||||||
|
const [value, setValue] = useState(null);
|
||||||
|
const [open, toggleOpen] = useState(false);
|
||||||
|
const [optionData, setOptionData] = useState([]);
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
//setDialogValue({
|
||||||
|
// name: '',
|
||||||
|
// street: '',
|
||||||
|
//});
|
||||||
|
console.log(dialogValue)
|
||||||
|
axios.post(baseURL+'/markets/', {
|
||||||
|
name: dialogValue.name,
|
||||||
|
street: dialogValue.street,
|
||||||
|
street_number: dialogValue.streetNum,
|
||||||
|
zip_code: dialogValue.zip,
|
||||||
|
city: dialogValue.city,
|
||||||
|
phone: dialogValue.phone
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
axios.get(baseURL+"/market")
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
setOptionData(data);
|
||||||
|
})
|
||||||
|
.then(function (res) {
|
||||||
|
console.log(res);
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
toggleOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const [dialogValue, setDialogValue] = useState({
|
||||||
|
name: '',
|
||||||
|
street: '',
|
||||||
|
streetNum: 0,
|
||||||
|
zip: '',
|
||||||
|
city: '',
|
||||||
|
phone: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
setValue({
|
||||||
|
name: dialogValue.name,
|
||||||
|
street: dialogValue.street,
|
||||||
|
streetNum: parseInt(dialogValue.streetNum,10),
|
||||||
|
zip: parseInt(dialogValue.zip,10),
|
||||||
|
city: dialogValue.city,
|
||||||
|
phone: dialogValue.phone
|
||||||
|
});
|
||||||
|
|
||||||
|
handleClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
axios.get(baseURL+"/markets")
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data;
|
||||||
|
//console.log(data)
|
||||||
|
setOptionData(data);
|
||||||
|
})
|
||||||
|
},[])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<Autocomplete
|
||||||
|
value={value}
|
||||||
|
onChange={(event, newValue) => {
|
||||||
|
if (typeof newValue === 'string') {
|
||||||
|
// timeout to avoid instant validation of the dialog's form.
|
||||||
|
setTimeout(() => {
|
||||||
|
toggleOpen(true);
|
||||||
|
console.log('this')
|
||||||
|
setDialogValue({
|
||||||
|
name: newValue,
|
||||||
|
street: '',
|
||||||
|
streetNum: 0,
|
||||||
|
zip: '',
|
||||||
|
city: '',
|
||||||
|
phone: ''
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (newValue && newValue.inputValue) {
|
||||||
|
toggleOpen(true);
|
||||||
|
setDialogValue({
|
||||||
|
name: newValue.inputValue,
|
||||||
|
street: '',
|
||||||
|
streetNum: 0,
|
||||||
|
zip: '',
|
||||||
|
city: '',
|
||||||
|
phone: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setValue(newValue);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
filterOptions={(options, params) => {
|
||||||
|
const filtered = filter(options, params);
|
||||||
|
|
||||||
|
if (params.inputValue !== '') {
|
||||||
|
filtered.push({
|
||||||
|
inputValue: params.inputValue,
|
||||||
|
name: `Add "${params.inputValue}"`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered;
|
||||||
|
}}
|
||||||
|
id="free-solo-dialog"
|
||||||
|
options={optionData}
|
||||||
|
getOptionLabel={(option) => {
|
||||||
|
// e.g value selected with enter, right from the input
|
||||||
|
if (typeof option === 'string') {
|
||||||
|
return option;
|
||||||
|
}
|
||||||
|
if (option.inputValue) {
|
||||||
|
return option.inputValue;
|
||||||
|
}
|
||||||
|
return option.name;
|
||||||
|
}}
|
||||||
|
selectOnFocus
|
||||||
|
clearOnBlur
|
||||||
|
handleHomeEndKeys
|
||||||
|
renderOption={(props, option) => <li {...props}>{option.name}</li>}
|
||||||
|
sx={{ width: 300 }}
|
||||||
|
freeSolo
|
||||||
|
renderInput={(params) => <TextField {...params} label="Markt auswählen" />}
|
||||||
|
/>
|
||||||
|
<Dialog open={open} onClose={handleClose}>
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<DialogTitle>Neuen Markt hinzufügen</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogContentText>
|
||||||
|
Ist der Markt noch nicht in der Liste? Dann füge ihn hinzu.
|
||||||
|
</DialogContentText>
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<TextField
|
||||||
|
autoFocus
|
||||||
|
fullWidth
|
||||||
|
margin="dense"
|
||||||
|
id="name"
|
||||||
|
error={dialogValue.name === ''}
|
||||||
|
value={dialogValue.name}
|
||||||
|
onChange={(event) =>
|
||||||
|
setDialogValue({
|
||||||
|
...dialogValue,
|
||||||
|
name: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
label="Name"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={9}>
|
||||||
|
<TextField
|
||||||
|
margin="dense"
|
||||||
|
fullWidth
|
||||||
|
id="street"
|
||||||
|
error={dialogValue.street === ''}
|
||||||
|
//value={dialogValue.street}
|
||||||
|
onChange={(event) =>
|
||||||
|
setDialogValue({
|
||||||
|
...dialogValue,
|
||||||
|
street: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
label="Straße"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={2}>
|
||||||
|
<TextField
|
||||||
|
margin="dense"
|
||||||
|
id="streetnum"
|
||||||
|
fullWidth
|
||||||
|
//value={dialogValue.streetNum}
|
||||||
|
error={dialogValue.streetNum === 0}
|
||||||
|
onChange={(event) =>
|
||||||
|
setDialogValue({
|
||||||
|
...dialogValue,
|
||||||
|
streetNum: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
label="Nr."
|
||||||
|
type="number"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={4}>
|
||||||
|
<TextField
|
||||||
|
margin="dense"
|
||||||
|
id="zip"
|
||||||
|
fullWidth
|
||||||
|
error={dialogValue.zip === ''}
|
||||||
|
//helperText="Incorrect entry."
|
||||||
|
//value={dialogValue.zip}
|
||||||
|
onChange={(event) =>
|
||||||
|
setDialogValue({
|
||||||
|
...dialogValue,
|
||||||
|
zip: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
label="PLZ"
|
||||||
|
type="number"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={8}>
|
||||||
|
<TextField
|
||||||
|
margin="dense"
|
||||||
|
id="city"
|
||||||
|
fullWidth
|
||||||
|
error={dialogValue.city === ''}
|
||||||
|
//value={dialogValue.city}
|
||||||
|
onChange={(event) =>
|
||||||
|
setDialogValue({
|
||||||
|
...dialogValue,
|
||||||
|
city: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
label="Stadt"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<TextField
|
||||||
|
margin="dense"
|
||||||
|
id="phone"
|
||||||
|
fullWidth
|
||||||
|
//value={dialogValue.tel}
|
||||||
|
onChange={(event) =>
|
||||||
|
setDialogValue({
|
||||||
|
...dialogValue,
|
||||||
|
tel: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
label="Telefon"
|
||||||
|
type="text"
|
||||||
|
variant="standard"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button
|
||||||
|
onClick={handleClose}
|
||||||
|
>
|
||||||
|
Abbrechen
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={dialogValue.name === "" ||
|
||||||
|
dialogValue.street === "" ||
|
||||||
|
dialogValue.streetNum === 0 ||
|
||||||
|
dialogValue.zip === "" ||
|
||||||
|
dialogValue.city === ""
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Hinzufügen</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</form>
|
||||||
|
</Dialog>
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SelectMarketField
|
||||||
102
reactFrontend/src/components/upload-files.component.js
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
import React from "react";
|
||||||
|
import {useState, useEffect} from 'react'
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { styled } from '@mui/material/styles';
|
||||||
|
import LinearProgress from '@mui/material/LinearProgress';
|
||||||
|
import { Box, Typography, Button } from '@mui/material';
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
const baseURL = "http://localhost:8000/api"
|
||||||
|
|
||||||
|
const Input = styled('input')({
|
||||||
|
display: 'none',
|
||||||
|
});
|
||||||
|
|
||||||
|
function LinearProgressWithLabel(props) {
|
||||||
|
return (
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center' }}>
|
||||||
|
<Box sx={{ width: '100%', mr: 1 }}>
|
||||||
|
<LinearProgress variant="determinate" {...props} />
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ minWidth: 35 }}>
|
||||||
|
<Typography variant="body2" color="text.secondary">{`${Math.round(
|
||||||
|
props.value,
|
||||||
|
)}%`}</Typography>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
LinearProgressWithLabel.propTypes = {
|
||||||
|
/**
|
||||||
|
* The value of the progress indicator for the determinate and buffer variants.
|
||||||
|
* Value between 0 and 100.
|
||||||
|
*/
|
||||||
|
value: PropTypes.number.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
const UploadFiles = (props) => {
|
||||||
|
const { apiURL, fileName, buttonText, applyBinarize, debug } = props;
|
||||||
|
|
||||||
|
const [progress, setProgress] = useState(0);
|
||||||
|
const [uploadFile, setUploadFile] = useState(0);
|
||||||
|
|
||||||
|
const handleUploadSelection = (e) => {
|
||||||
|
console.log(e.target.files[0])
|
||||||
|
setUploadFile(e.target.files[0]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpload = (event) => {
|
||||||
|
event.preventDefault()
|
||||||
|
const formData = new FormData();
|
||||||
|
console.log(uploadFile)
|
||||||
|
formData.append("fileTitle", fileName);
|
||||||
|
formData.append("applyBinarize", applyBinarize);
|
||||||
|
formData.append("debug", debug);
|
||||||
|
formData.append("uploadedFile", uploadFile);
|
||||||
|
axios.post(baseURL+apiURL, formData, {
|
||||||
|
headers: {
|
||||||
|
'content-type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return(
|
||||||
|
<div style={{ height: 100, width: '100%' }}>
|
||||||
|
<Box sx={{ width: '100%' }}>
|
||||||
|
<LinearProgressWithLabel value={progress} />
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<label htmlFor="contained-button-file">
|
||||||
|
<Input
|
||||||
|
accept="image/*"
|
||||||
|
id="contained-button-file"
|
||||||
|
multiple type="file"
|
||||||
|
onChange={handleUploadSelection}
|
||||||
|
/>
|
||||||
|
<Button variant="contained" component="span">
|
||||||
|
Bild auswählen
|
||||||
|
</Button>
|
||||||
|
<div className="file-name">
|
||||||
|
{uploadFile && uploadFile.length > 0 ? uploadFile[0].name : null}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
component="span"
|
||||||
|
onClick={handleUpload}
|
||||||
|
>
|
||||||
|
{buttonText}
|
||||||
|
</Button>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UploadFiles
|
||||||
50
reactFrontend/src/components/usePrompt.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* Prompts a user when they exit the page
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useCallback, useContext, useEffect } from 'react';
|
||||||
|
import { UNSAFE_NavigationContext as NavigationContext } from 'react-router-dom';
|
||||||
|
|
||||||
|
function useConfirmExit(confirmExit, when = true) {
|
||||||
|
const navigator = useContext(NavigationContext);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!when) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const push = navigator.push;
|
||||||
|
|
||||||
|
navigator.push = (...args) => {
|
||||||
|
const result = confirmExit();
|
||||||
|
if (result !== false) {
|
||||||
|
push(...args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
navigator.push = push;
|
||||||
|
};
|
||||||
|
}, [navigator, confirmExit, when]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function usePrompt(message, when = true) {
|
||||||
|
useEffect(() => {
|
||||||
|
if (when) {
|
||||||
|
window.onbeforeunload = function () {
|
||||||
|
return message;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.onbeforeunload = null;
|
||||||
|
};
|
||||||
|
}, [message, when]);
|
||||||
|
|
||||||
|
const confirmExit = useCallback(() => {
|
||||||
|
const confirm = window.confirm(message);
|
||||||
|
return confirm;
|
||||||
|
}, [message]);
|
||||||
|
useConfirmExit(confirmExit, when);
|
||||||
|
}
|
||||||
|
|
||||||
8
reactFrontend/src/http-common.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
export default axios.create({
|
||||||
|
baseURL: "http://localhost:8000/api",
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
19
reactFrontend/src/index.css
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||||
|
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||||
|
sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||||
|
monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
17
reactFrontend/src/index.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom/client';
|
||||||
|
import './index.css';
|
||||||
|
import App from './App';
|
||||||
|
import reportWebVitals from './reportWebVitals';
|
||||||
|
|
||||||
|
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||||
|
root.render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>
|
||||||
|
);
|
||||||
|
|
||||||
|
// If you want to start measuring performance in your app, pass a function
|
||||||
|
// to log results (for example: reportWebVitals(console.log))
|
||||||
|
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||||
|
reportWebVitals();
|
||||||
1
reactFrontend/src/logo.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 2.6 KiB |
13
reactFrontend/src/reportWebVitals.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const reportWebVitals = onPerfEntry => {
|
||||||
|
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||||
|
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||||
|
getCLS(onPerfEntry);
|
||||||
|
getFID(onPerfEntry);
|
||||||
|
getFCP(onPerfEntry);
|
||||||
|
getLCP(onPerfEntry);
|
||||||
|
getTTFB(onPerfEntry);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default reportWebVitals;
|
||||||
15
reactFrontend/src/services/upload-files.service.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import http from "../http-common";
|
||||||
|
|
||||||
|
class UploadFilesService {
|
||||||
|
upload(file, onUploadProgress) {
|
||||||
|
let formData = new FormData();
|
||||||
|
formData.append("file", file);
|
||||||
|
return http.post("/purchase/post_receipe/", formData, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "multipart/form-data",
|
||||||
|
},
|
||||||
|
onUploadProgress,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default new UploadFilesService();
|
||||||
5
reactFrontend/src/setupTests.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||||
|
// allows you to do things like:
|
||||||
|
// expect(element).toHaveTextContent(/react/i)
|
||||||
|
// learn more: https://github.com/testing-library/jest-dom
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
11173
reactFrontend/yarn.lock
Normal file
73
receipeServer/README.md
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
# Project Name Backend
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The backend of the project is a Django web application that provides an API for parsing receipts and storing the extracted information in a PostgreSQL database.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
The backend requires the following dependencies:
|
||||||
|
|
||||||
|
- Python 3.6 or higher
|
||||||
|
- Django 3.2 or higher
|
||||||
|
- NumPy 1.20 or higher
|
||||||
|
- SciPy 1.6 or higher
|
||||||
|
- psycopg2 2.8 or higher
|
||||||
|
|
||||||
|
To install the dependencies, run the following command:
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install django numpy scipy psycopg2
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
To use the backend, follow these steps:
|
||||||
|
|
||||||
|
1. Clone the repository to your local machine.
|
||||||
|
2. Install the dependencies as described in the Installation section.
|
||||||
|
3. Create a PostgreSQL database and configure the database settings in the `settings.py` file.
|
||||||
|
4. Run the Django server by executing the following command in the project directory:
|
||||||
|
|
||||||
|
```
|
||||||
|
python manage.py runserver
|
||||||
|
```
|
||||||
|
|
||||||
|
5. The API endpoints are available at `http://localhost:8000/api/`.
|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
|
||||||
|
The backend consists of the following components:
|
||||||
|
|
||||||
|
- `receipe/views.py`: Defines the views for the parser web application.
|
||||||
|
- `receipe/models.py`: Defines the models for the parser database.
|
||||||
|
- `receipe/forms.py`: Defines the forms for the parser web application.
|
||||||
|
- `receipe/parser.py`: Defines the parser class that extracts information from the receipt image.
|
||||||
|
- `receipe/alignment.py`: Defines the linear alignment class that aligns the extracted information with the known articles in the database.
|
||||||
|
- `receipe/serializers.py`: Defines the serializers for the parser API.
|
||||||
|
|
||||||
|
The backend uses the Django web framework and the Django REST framework to provide the API endpoints. The backend also uses the NumPy and SciPy libraries for image processing and clustering, and the psycopg2 library for interacting with the PostgreSQL database.
|
||||||
|
|
||||||
|
The backend provides the following API endpoints:
|
||||||
|
|
||||||
|
- `GET /api/articles/`: Returns a list of all articles in the database.
|
||||||
|
- `POST /api/articles/`: Adds a new article to the database.
|
||||||
|
- `GET /api/articles/<id>/`: Returns the details of a specific article.
|
||||||
|
- `PUT /api/articles/<id>/`: Updates the details of a specific article.
|
||||||
|
- `DELETE /api/articles/<id>/`: Deletes a specific article from the database.
|
||||||
|
- ...
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
The backend has the following limitations:
|
||||||
|
|
||||||
|
- The backend assumes that the receipt image is of good quality and is properly aligned.
|
||||||
|
- The backend may not be able to extract information from handwritten receipts or receipts with non-standard formats.
|
||||||
|
- The backend may not be able to match the extracted information with the known articles in the database if the names are misspelled or the database is incomplete.
|
||||||
|
|
||||||
|
## Future Work
|
||||||
|
|
||||||
|
The backend can be improved in the following ways:
|
||||||
|
|
||||||
|
- Use machine learning algorithms to improve the accuracy of the article matching.
|
||||||
|
- Use deep learning / conventional algorithms to detect and correct image distortions and misalignments.
|
||||||
34
receipeServer/category.dump
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"model": "receipe.category",
|
||||||
|
"pk": 1,
|
||||||
|
"fields": {
|
||||||
|
"name": "Artikel",
|
||||||
|
"level": "1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "receipe.category",
|
||||||
|
"pk": 2,
|
||||||
|
"fields": {
|
||||||
|
"name": "Haushaltsartikel",
|
||||||
|
"level": "1_1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "receipe.category",
|
||||||
|
"pk": 3,
|
||||||
|
"fields": {
|
||||||
|
"name": "Hygieneartikel",
|
||||||
|
"level": "1_2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "receipe.category",
|
||||||
|
"pk": 4,
|
||||||
|
"fields": {
|
||||||
|
"name": "Lebensmittel",
|
||||||
|
"level": "1_3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
23
receipeServer/frontend2/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
70
receipeServer/frontend2/README.md
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
# Getting Started with Create React App
|
||||||
|
|
||||||
|
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||||
|
|
||||||
|
## Available Scripts
|
||||||
|
|
||||||
|
In the project directory, you can run:
|
||||||
|
|
||||||
|
### `npm start`
|
||||||
|
|
||||||
|
Runs the app in the development mode.\
|
||||||
|
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
||||||
|
|
||||||
|
The page will reload when you make changes.\
|
||||||
|
You may also see any lint errors in the console.
|
||||||
|
|
||||||
|
### `npm test`
|
||||||
|
|
||||||
|
Launches the test runner in the interactive watch mode.\
|
||||||
|
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||||
|
|
||||||
|
### `npm run build`
|
||||||
|
|
||||||
|
Builds the app for production to the `build` folder.\
|
||||||
|
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||||
|
|
||||||
|
The build is minified and the filenames include the hashes.\
|
||||||
|
Your app is ready to be deployed!
|
||||||
|
|
||||||
|
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||||
|
|
||||||
|
### `npm run eject`
|
||||||
|
|
||||||
|
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
||||||
|
|
||||||
|
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||||
|
|
||||||
|
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
||||||
|
|
||||||
|
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
||||||
|
|
||||||
|
## Learn More
|
||||||
|
|
||||||
|
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||||
|
|
||||||
|
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||||
|
|
||||||
|
### Code Splitting
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||||
|
|
||||||
|
### Analyzing the Bundle Size
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||||
|
|
||||||
|
### Making a Progressive Web App
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||||
|
|
||||||
|
### Advanced Configuration
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||||
|
|
||||||
|
### Deployment
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||||
|
|
||||||
|
### `npm run build` fails to minify
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
||||||
28134
receipeServer/frontend2/package-lock.json
generated
Normal file
40
receipeServer/frontend2/package.json
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@mantine/core": "^4.1.3",
|
||||||
|
"@mantine/hooks": "^4.1.3",
|
||||||
|
"@testing-library/jest-dom": "^5.16.4",
|
||||||
|
"@testing-library/react": "^12.1.4",
|
||||||
|
"@testing-library/user-event": "^13.5.0",
|
||||||
|
"react": "^18.0.0",
|
||||||
|
"react-dom": "^18.0.0",
|
||||||
|
"react-scripts": "5.0.0",
|
||||||
|
"web-vitals": "^2.1.4"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "react-scripts start",
|
||||||
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": [
|
||||||
|
"react-app",
|
||||||
|
"react-app/jest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
receipeServer/frontend2/public/favicon.ico
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
43
receipeServer/frontend2/public/index.html
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta name="theme-color" content="#000000" />
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content="Web site created using create-react-app"
|
||||||
|
/>
|
||||||
|
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||||
|
<!--
|
||||||
|
manifest.json provides metadata used when your web app is installed on a
|
||||||
|
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||||
|
-->
|
||||||
|
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||||
|
<!--
|
||||||
|
Notice the use of %PUBLIC_URL% in the tags above.
|
||||||
|
It will be replaced with the URL of the `public` folder during the build.
|
||||||
|
Only files inside the `public` folder can be referenced from the HTML.
|
||||||
|
|
||||||
|
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||||
|
work correctly both with client-side routing and a non-root public URL.
|
||||||
|
Learn how to configure a non-root public URL by running `npm run build`.
|
||||||
|
-->
|
||||||
|
<title>React App</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
<!--
|
||||||
|
This HTML file is a template.
|
||||||
|
If you open it directly in the browser, you will see an empty page.
|
||||||
|
|
||||||
|
You can add webfonts, meta tags, or analytics to this file.
|
||||||
|
The build step will place the bundled scripts into the <body> tag.
|
||||||
|
|
||||||
|
To begin the development, run `npm start` or `yarn start`.
|
||||||
|
To create a production bundle, use `npm run build` or `yarn build`.
|
||||||
|
-->
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
BIN
receipeServer/frontend2/public/logo192.png
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
receipeServer/frontend2/public/logo512.png
Normal file
|
After Width: | Height: | Size: 9.4 KiB |
25
receipeServer/frontend2/public/manifest.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"short_name": "React App",
|
||||||
|
"name": "Create React App Sample",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "favicon.ico",
|
||||||
|
"sizes": "64x64 32x32 24x24 16x16",
|
||||||
|
"type": "image/x-icon"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "logo192.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "192x192"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "logo512.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "512x512"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"start_url": ".",
|
||||||
|
"display": "standalone",
|
||||||
|
"theme_color": "#000000",
|
||||||
|
"background_color": "#ffffff"
|
||||||
|
}
|
||||||
3
receipeServer/frontend2/public/robots.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# https://www.robotstxt.org/robotstxt.html
|
||||||
|
User-agent: *
|
||||||
|
Disallow:
|
||||||
38
receipeServer/frontend2/src/App.css
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
.App {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-logo {
|
||||||
|
height: 40vmin;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: no-preference) {
|
||||||
|
.App-logo {
|
||||||
|
animation: App-logo-spin infinite 20s linear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-header {
|
||||||
|
background-color: #282c34;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: calc(10px + 2vmin);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-link {
|
||||||
|
color: #61dafb;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes App-logo-spin {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
receipeServer/frontend2/src/App.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import './styles/App.css';
|
||||||
|
|
||||||
|
import { AppShell, Navbar } from '@mantine/core'
|
||||||
|
|
||||||
|
const App = () => {
|
||||||
|
<AppShell
|
||||||
|
navbar={
|
||||||
|
<Navbar
|
||||||
|
width={{ base: 300 }}
|
||||||
|
height='100vh'
|
||||||
|
>
|
||||||
|
{/* Navbar Content */}
|
||||||
|
</Navbar>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{/* Your application here */}
|
||||||
|
</AppShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export default App;
|
||||||
8
receipeServer/frontend2/src/App.test.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import App from './App';
|
||||||
|
|
||||||
|
test('renders learn react link', () => {
|
||||||
|
render(<App />);
|
||||||
|
const linkElement = screen.getByText(/learn react/i);
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
});
|
||||||
13
receipeServer/frontend2/src/index.css
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||||
|
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||||
|
sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||||
|
monospace;
|
||||||
|
}
|
||||||
17
receipeServer/frontend2/src/index.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import './index.css';
|
||||||
|
import App from './App';
|
||||||
|
import reportWebVitals from './reportWebVitals';
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>,
|
||||||
|
document.getElementById('root')
|
||||||
|
);
|
||||||
|
|
||||||
|
// If you want to start measuring performance in your app, pass a function
|
||||||
|
// to log results (for example: reportWebVitals(console.log))
|
||||||
|
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||||
|
reportWebVitals();
|
||||||
1
receipeServer/frontend2/src/logo.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 2.6 KiB |
13
receipeServer/frontend2/src/reportWebVitals.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const reportWebVitals = onPerfEntry => {
|
||||||
|
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||||
|
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||||
|
getCLS(onPerfEntry);
|
||||||
|
getFID(onPerfEntry);
|
||||||
|
getFCP(onPerfEntry);
|
||||||
|
getLCP(onPerfEntry);
|
||||||
|
getTTFB(onPerfEntry);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default reportWebVitals;
|
||||||
5
receipeServer/frontend2/src/setupTests.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||||
|
// allows you to do things like:
|
||||||
|
// expect(element).toHaveTextContent(/react/i)
|
||||||
|
// learn more: https://github.com/testing-library/jest-dom
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/acorn
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../acorn/bin/acorn
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/ansi-html
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../ansi-html-community/bin/ansi-html
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/autoprefixer
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../autoprefixer/bin/autoprefixer
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/browserslist
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../browserslist/cli.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/css-blank-pseudo
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../css-blank-pseudo/dist/cli.cjs
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/css-has-pseudo
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../css-has-pseudo/dist/cli.cjs
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/css-prefers-color-scheme
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../css-prefers-color-scheme/dist/cli.cjs
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/cssesc
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../cssesc/bin/cssesc
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/envinfo
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../envinfo/dist/cli.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/he
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../he/bin/he
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/html-minifier-terser
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../html-minifier-terser/cli.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/import-local-fixture
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../import-local/fixtures/cli.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/is-docker
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../is-docker/cli.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/jsesc
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../jsesc/bin/jsesc
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/json5
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../json5/lib/cli.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/loose-envify
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../loose-envify/cli.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/mime
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../mime/cli.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/mkdirp
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../mkdirp/bin/cmd.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/multicast-dns
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../multicast-dns/cli.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/nanoid
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../nanoid/bin/nanoid.cjs
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/node-which
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../which/bin/node-which
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/parser
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../@babel/parser/bin/babel-parser.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/regjsparser
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../regjsparser/bin/parser
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/resolve
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../resolve/bin/resolve
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/rimraf
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../rimraf/bin.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/semver
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../semver/bin/semver.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/terser
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../terser/bin/terser
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/uuid
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../uuid/dist/bin/uuid
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/webpack
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../webpack/bin/webpack.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/webpack-cli
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../webpack-cli/bin/cli.js
|
||||||
1
receipeServer/frontend_old/node_modules/.bin/webpack-dev-server
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../webpack-dev-server/bin/webpack-dev-server.js
|
||||||
7586
receipeServer/frontend_old/node_modules/.package-lock.json
generated
vendored
Normal file
202
receipeServer/frontend_old/node_modules/@ampproject/remapping/LICENSE
generated
vendored
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright 2019 Google LLC
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
218
receipeServer/frontend_old/node_modules/@ampproject/remapping/README.md
generated
vendored
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
# @ampproject/remapping
|
||||||
|
|
||||||
|
> Remap sequential sourcemaps through transformations to point at the original source code
|
||||||
|
|
||||||
|
Remapping allows you to take the sourcemaps generated through transforming your code and "remap"
|
||||||
|
them to the original source locations. Think "my minified code, transformed with babel and bundled
|
||||||
|
with webpack", all pointing to the correct location in your original source code.
|
||||||
|
|
||||||
|
With remapping, none of your source code transformations need to be aware of the input's sourcemap,
|
||||||
|
they only need to generate an output sourcemap. This greatly simplifies building custom
|
||||||
|
transformations (think a find-and-replace).
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install @ampproject/remapping
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
function remapping(
|
||||||
|
map: SourceMap | SourceMap[],
|
||||||
|
loader: (file: string, ctx: LoaderContext) => (SourceMap | null | undefined),
|
||||||
|
options?: { excludeContent: boolean, decodedMappings: boolean }
|
||||||
|
): SourceMap;
|
||||||
|
|
||||||
|
// LoaderContext gives the loader the importing sourcemap, tree depth, the ability to override the
|
||||||
|
// "source" location (where child sources are resolved relative to, or the location of original
|
||||||
|
// source), and the ability to override the "content" of an original source for inclusion in the
|
||||||
|
// output sourcemap.
|
||||||
|
type LoaderContext = {
|
||||||
|
readonly importer: string;
|
||||||
|
readonly depth: number;
|
||||||
|
source: string;
|
||||||
|
content: string | null | undefined;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`remapping` takes the final output sourcemap, and a `loader` function. For every source file pointer
|
||||||
|
in the sourcemap, the `loader` will be called with the resolved path. If the path itself represents
|
||||||
|
a transformed file (it has a sourcmap associated with it), then the `loader` should return that
|
||||||
|
sourcemap. If not, the path will be treated as an original, untransformed source code.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Babel transformed "helloworld.js" into "transformed.js"
|
||||||
|
const transformedMap = JSON.stringify({
|
||||||
|
file: 'transformed.js',
|
||||||
|
// 1st column of 2nd line of output file translates into the 1st source
|
||||||
|
// file, line 3, column 2
|
||||||
|
mappings: ';CAEE',
|
||||||
|
sources: ['helloworld.js'],
|
||||||
|
version: 3,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Uglify minified "transformed.js" into "transformed.min.js"
|
||||||
|
const minifiedTransformedMap = JSON.stringify({
|
||||||
|
file: 'transformed.min.js',
|
||||||
|
// 0th column of 1st line of output file translates into the 1st source
|
||||||
|
// file, line 2, column 1.
|
||||||
|
mappings: 'AACC',
|
||||||
|
names: [],
|
||||||
|
sources: ['transformed.js'],
|
||||||
|
version: 3,
|
||||||
|
});
|
||||||
|
|
||||||
|
const remapped = remapping(
|
||||||
|
minifiedTransformedMap,
|
||||||
|
(file, ctx) => {
|
||||||
|
|
||||||
|
// The "transformed.js" file is an transformed file.
|
||||||
|
if (file === 'transformed.js') {
|
||||||
|
// The root importer is empty.
|
||||||
|
console.assert(ctx.importer === '');
|
||||||
|
// The depth in the sourcemap tree we're currently loading.
|
||||||
|
// The root `minifiedTransformedMap` is depth 0, and its source children are depth 1, etc.
|
||||||
|
console.assert(ctx.depth === 1);
|
||||||
|
|
||||||
|
return transformedMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loader will be called to load transformedMap's source file pointers as well.
|
||||||
|
console.assert(file === 'helloworld.js');
|
||||||
|
// `transformed.js`'s sourcemap points into `helloworld.js`.
|
||||||
|
console.assert(ctx.importer === 'transformed.js');
|
||||||
|
// This is a source child of `transformed`, which is a source child of `minifiedTransformedMap`.
|
||||||
|
console.assert(ctx.depth === 2);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(remapped);
|
||||||
|
// {
|
||||||
|
// file: 'transpiled.min.js',
|
||||||
|
// mappings: 'AAEE',
|
||||||
|
// sources: ['helloworld.js'],
|
||||||
|
// version: 3,
|
||||||
|
// };
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example, `loader` will be called twice:
|
||||||
|
|
||||||
|
1. `"transformed.js"`, the first source file pointer in the `minifiedTransformedMap`. We return the
|
||||||
|
associated sourcemap for it (its a transformed file, after all) so that sourcemap locations can
|
||||||
|
be traced through it into the source files it represents.
|
||||||
|
2. `"helloworld.js"`, our original, unmodified source code. This file does not have a sourcemap, so
|
||||||
|
we return `null`.
|
||||||
|
|
||||||
|
The `remapped` sourcemap now points from `transformed.min.js` into locations in `helloworld.js`. If
|
||||||
|
you were to read the `mappings`, it says "0th column of the first line output line points to the 1st
|
||||||
|
column of the 2nd line of the file `helloworld.js`".
|
||||||
|
|
||||||
|
### Multiple transformations of a file
|
||||||
|
|
||||||
|
As a convenience, if you have multiple single-source transformations of a file, you may pass an
|
||||||
|
array of sourcemap files in the order of most-recent transformation sourcemap first. Note that this
|
||||||
|
changes the `importer` and `depth` of each call to our loader. So our above example could have been
|
||||||
|
written as:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const remapped = remapping(
|
||||||
|
[minifiedTransformedMap, transformedMap],
|
||||||
|
() => null
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(remapped);
|
||||||
|
// {
|
||||||
|
// file: 'transpiled.min.js',
|
||||||
|
// mappings: 'AAEE',
|
||||||
|
// sources: ['helloworld.js'],
|
||||||
|
// version: 3,
|
||||||
|
// };
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced control of the loading graph
|
||||||
|
|
||||||
|
#### `source`
|
||||||
|
|
||||||
|
The `source` property can overridden to any value to change the location of the current load. Eg,
|
||||||
|
for an original source file, it allows us to change the location to the original source regardless
|
||||||
|
of what the sourcemap source entry says. And for transformed files, it allows us to change the
|
||||||
|
relative resolving location for child sources of the loaded sourcemap.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const remapped = remapping(
|
||||||
|
minifiedTransformedMap,
|
||||||
|
(file, ctx) => {
|
||||||
|
|
||||||
|
if (file === 'transformed.js') {
|
||||||
|
// We pretend the transformed.js file actually exists in the 'src/' directory. When the nested
|
||||||
|
// source files are loaded, they will now be relative to `src/`.
|
||||||
|
ctx.source = 'src/transformed.js';
|
||||||
|
return transformedMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.assert(file === 'src/helloworld.js');
|
||||||
|
// We could futher change the source of this original file, eg, to be inside a nested directory
|
||||||
|
// itself. This will be reflected in the remapped sourcemap.
|
||||||
|
ctx.source = 'src/nested/transformed.js';
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(remapped);
|
||||||
|
// {
|
||||||
|
// …,
|
||||||
|
// sources: ['src/nested/helloworld.js'],
|
||||||
|
// };
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### `content`
|
||||||
|
|
||||||
|
The `content` property can be overridden when we encounter an original source file. Eg, this allows
|
||||||
|
you to manually provide the source content of the original file regardless of whether the
|
||||||
|
`sourcesContent` field is present in the parent sourcemap. It can also be set to `null` to remove
|
||||||
|
the source content.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const remapped = remapping(
|
||||||
|
minifiedTransformedMap,
|
||||||
|
(file, ctx) => {
|
||||||
|
|
||||||
|
if (file === 'transformed.js') {
|
||||||
|
// transformedMap does not include a `sourcesContent` field, so usually the remapped sourcemap
|
||||||
|
// would not include any `sourcesContent` values.
|
||||||
|
return transformedMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.assert(file === 'helloworld.js');
|
||||||
|
// We can read the file to provide the source content.
|
||||||
|
ctx.content = fs.readFileSync(file, 'utf8');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(remapped);
|
||||||
|
// {
|
||||||
|
// …,
|
||||||
|
// sourcesContent: [
|
||||||
|
// 'console.log("Hello world!")',
|
||||||
|
// ],
|
||||||
|
// };
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
#### excludeContent
|
||||||
|
|
||||||
|
By default, `excludeContent` is `false`. Passing `{ excludeContent: true }` will exclude the
|
||||||
|
`sourcesContent` field from the returned sourcemap. This is mainly useful when you want to reduce
|
||||||
|
the size out the sourcemap.
|
||||||
|
|
||||||
|
#### decodedMappings
|
||||||
|
|
||||||
|
By default, `decodedMappings` is `false`. Passing `{ decodedMappings: true }` will leave the
|
||||||
|
`mappings` field in a [decoded state](https://github.com/rich-harris/sourcemap-codec) instead of
|
||||||
|
encoding into a VLQ string.
|
||||||