├── .circleci └── config.yml ├── .devcontainer ├── Dockerfile ├── database.yml ├── db │ └── docker-entrypoint-initdb.d │ │ └── create-test-database.sql ├── devcontainer.json └── docker-compose.yml ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── stale-issues.yml ├── .gitignore ├── Gemfile ├── LICENSE ├── README.ja.md ├── README.md ├── after_init.rb ├── app ├── controllers │ └── view_customizes_controller.rb ├── helpers │ └── view_customizes_helper.rb ├── models │ └── view_customize.rb └── views │ ├── settings │ └── _view_customize_settings.html.erb │ └── view_customizes │ ├── _form.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb ├── assets ├── images │ ├── disable.png │ ├── enable.png │ └── view_customize.png └── stylesheets │ └── view_customize.css ├── config ├── locales │ ├── en.yml │ ├── ja.yml │ ├── zh-TW.yml │ └── zh.yml └── routes.rb ├── db └── migrate │ ├── 001_create_view_customizes.rb │ ├── 002_add_column_view_customizes.rb │ ├── 003_add_insertion_position_to_view_customizes.rb │ ├── 004_add_comments_to_view_customizes.rb │ ├── 005_change_code_limit_on_view_customizes.rb │ ├── 006_add_project_pattern_to_view_customizes.rb │ ├── 007_change_path_pattern_default_on_view_customizes.rb │ └── 008_change_default_bugfix_on_view_customizes.rb ├── init.rb ├── lib └── redmine_view_customize │ └── view_hook.rb ├── screenshots ├── admin.en.png ├── detail.en.png ├── enable_private.en.png ├── example.en.png ├── list_edit.en.png ├── list_new.en.png ├── my_account.en.png ├── new.en.png └── plugin_configure.en.png └── test ├── fixtures └── view_customizes.yml ├── functional └── view_customizes_controller_test.rb ├── test_helper.rb └── unit └── view_customize_view_hook_test.rb /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | orbs: 4 | redmine-plugin: agileware-jp/redmine-plugin@3.8.0 5 | 6 | jobs: 7 | run_tests: 8 | parameters: 9 | redmine_version: 10 | type: string 11 | default: latest 12 | redmine_product: 13 | type: string 14 | default: redmine 15 | ruby_version: 16 | type: string 17 | default: "3.3" # https://github.com/redmine/redmine/blob/5.0.3/Gemfile#L3 18 | database: 19 | type: enum 20 | enum: 21 | - mysql 22 | - pg 23 | - mariadb 24 | - sqlite3 25 | default: pg 26 | executor: 27 | name: redmine-plugin/ruby-<< parameters.database >> 28 | ruby_version: << parameters.ruby_version >> 29 | steps: 30 | - checkout 31 | - redmine-plugin/download-redmine: 32 | version: << parameters.redmine_version >> 33 | product: << parameters.redmine_product >> 34 | - redmine-plugin/install-self 35 | - run: 36 | name: Rename to view_customize 37 | working_directory: redmine 38 | command: mv -v plugins/$CIRCLE_PROJECT_REPONAME plugins/view_customize 39 | - redmine-plugin/generate-database_yml 40 | - run: 41 | name: Install MagickWand library when rmagick.gem is used 42 | working_directory: redmine 43 | command: | 44 | set -eux -o pipefail 45 | # https://github.com/redmine/redmine/blob/4.0.9/Gemfile#L41 46 | grep -q 'gem "rmagick"' Gemfile || exit 0 47 | # rmagick.gem requires followings. 48 | sudo apt-get update 49 | sudo apt-get install -y libmagickwand-dev 50 | - run: 51 | working_directory: redmine 52 | command: touch Gemfile.local 53 | - redmine-plugin/bundle-install 54 | - redmine-plugin/test: 55 | plugin: view_customize 56 | - store_artifacts: 57 | path: redmine/tmp/screenshots 58 | destination: screenshots 59 | 60 | workflows: 61 | version: 2 62 | test: 63 | jobs: 64 | - run_tests: 65 | name: latest Redmine with PostgreSQL 66 | database: pg 67 | - run_tests: 68 | name: latest Redmine with MySQL 69 | database: mysql 70 | - run_tests: 71 | name: redmine-5.1.6 with PostgreSQL 72 | redmine_version: "5.1.6" 73 | ruby_version: "3.2" # https://github.com/redmine/redmine/blob/5.1.6/Gemfile#L3 74 | database: pg 75 | - run_tests: 76 | name: redmine-5.0.11 with PostgreSQL 77 | redmine_version: "5.0.11" 78 | ruby_version: "3.1" # https://github.com/redmine/redmine/blob/5.0.11/Gemfile#L3 79 | database: pg 80 | - run_tests: 81 | name: redmine-4.2 with PostgreSQL 82 | redmine_version: "4.2.10" 83 | ruby_version: "2.7" # https://github.com/redmine/redmine/blob/4.2.10/Gemfile#L3 84 | database: pg 85 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM redmine:6.0.3 2 | 3 | # 必要なパッケージをインストール 4 | RUN apt-get update && apt-get install -y \ 5 | build-essential \ 6 | libssl-dev \ 7 | libreadline-dev \ 8 | zlib1g-dev 9 | -------------------------------------------------------------------------------- /.devcontainer/database.yml: -------------------------------------------------------------------------------- 1 | production: 2 | adapter: postgresql 3 | host: "db" 4 | port: "5432" 5 | username: "postgres" 6 | password: "example" 7 | database: "postgres" 8 | encoding: "utf8" 9 | test: 10 | adapter: postgresql 11 | host: "db" 12 | port: "5432" 13 | username: "postgres" 14 | password: "example" 15 | database: "test" 16 | encoding: "utf8" 17 | -------------------------------------------------------------------------------- /.devcontainer/db/docker-entrypoint-initdb.d/create-test-database.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE test; 2 | GRANT ALL PRIVILEGES ON DATABASE test TO postgres; 3 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Redmine", 3 | "dockerComposeFile": "docker-compose.yml", 4 | "service": "redmine", 5 | "remoteUser": "redmine", 6 | "customizations": { 7 | "vscode": { 8 | "settings": { 9 | "terminal.integrated.defaultProfile.linux": "bash" 10 | } 11 | } 12 | }, 13 | "workspaceFolder": "/usr/src/redmine/plugins/view_customize", 14 | "postCreateCommand": "cd /usr/src/redmine && bundle config set without development && bundle install --verbose && bundle exec rails db:migrate:reset RAILS_ENV=test && bundle exec rake redmine:plugins:migrate RAILS_ENV=production && bundle exec rake redmine:plugins:migrate RAILS_ENV=test" 15 | } -------------------------------------------------------------------------------- /.devcontainer/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | redmine: 3 | build: 4 | context: . 5 | dockerfile: Dockerfile 6 | restart: always 7 | ports: 8 | - 8080:3000 9 | environment: 10 | REDMINE_DB_POSTGRES: db 11 | REDMINE_DB_PASSWORD: example 12 | volumes: 13 | - redmine-files:/usr/src/redmine/files 14 | - ./database.yml:/usr/src/redmine/config/database.yml 15 | - ./..:/usr/src/redmine/plugins/view_customize 16 | db: 17 | image: postgres:latest 18 | restart: unless-stopped 19 | volumes: 20 | - postgres-data:/var/lib/postgresql/data 21 | - ./db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d 22 | environment: 23 | POSTGRES_PASSWORD: example 24 | POSTGRES_DB: redmine 25 | volumes: 26 | redmine-files: 27 | postgres-data: 28 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: onozaty 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Summary 11 | 12 | 13 | ## Description 14 | 15 | 16 | ## Environment 17 | 18 | - View customize plugin version 19 | - Redmine version 20 | - Ruby version 21 | - Rails version 22 | - Installed other plugins 23 | 24 | You can get these informations from Redmine's information page. 25 | (E.g. http://example.com/admin/info) 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/stale-issues.yml: -------------------------------------------------------------------------------- 1 | name: Close inactive issues 2 | on: 3 | schedule: 4 | - cron: "30 1 * * *" 5 | 6 | jobs: 7 | close-issues: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/stale@v4 11 | with: 12 | repo-token: ${{ secrets.GITHUB_TOKEN }} 13 | stale-issue-message: "This issue is stale because it has been open for 60 days with no activity." 14 | close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." 15 | stale-issue-label: "stale" 16 | exempt-issue-labels: "bug,enhancement" 17 | days-before-issue-stale: 60 18 | days-before-issue-close: 14 19 | days-before-pr-stale: -1 20 | days-before-pr-close: -1 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | gem 'activerecord-compatible_legacy_migration' 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.ja.md: -------------------------------------------------------------------------------- 1 | # Redmine view customize plugin 2 | 3 | [![CircleCI](https://dl.circleci.com/status-badge/img/gh/onozaty/redmine-view-customize/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/onozaty/redmine-view-customize/tree/master) 4 | 5 | [Redmine](http://www.redmine.org)の画面をカスタマイズするためのプラグインです。 6 | 7 | ## 機能 8 | 9 | 条件に一致した画面に対して、JavaScript、CSS、HTMLを埋め込むことで、画面をカスタマイズします。 10 | 11 | ## インストール方法 12 | 13 | Redmineのプラグインディレクトリに、このリポジトリを`view_customize`としてクローンします。 14 | 15 | ``` 16 | cd {RAILS_ROOT}/plugins 17 | git clone https://github.com/onozaty/redmine-view-customize.git view_customize 18 | cd ../ 19 | bundle install --without development test 20 | bundle exec rake redmine:plugins:migrate RAILS_ENV=production 21 | ``` 22 | 23 | **注意: ディレクトリ名は`view_customize`とする必要があります。ディレクトリ名が異なると、プラグインの実行に失敗します。** 24 | 25 | ## 使用方法 26 | 27 | ### 追加 28 | 29 | プラグインをインストールすると、管理者メニューに「View customize」が追加されます。 30 | 31 | ![Screenshot of admin menu](screenshots/admin.en.png) 32 | 33 | 「View customize」を押下すると、一覧画面に遷移します。 34 | 35 | ![Screenshot of list new](screenshots/list_new.en.png) 36 | 37 | 「New view customize」を押下し、各種項目を入力します。 38 | 39 | ![Screenshot of new](screenshots/new.en.png) 40 | 41 | 「Path pattern」と「Project pattern」を使って、対象のページを指定します。 42 | どちらも指定されていなかった場合には、全てのページが対象になります。 43 | 44 | 「Path pattern」は正規表現でパスを指定します。 45 | 「Path pattern」が設定されていた場合、ページのパスが一致しないと、コードが挿入されません。 46 | 47 | 以下は設定例です。 48 | * `/issues$` : チケット一覧 49 | * `/issues/[0-9]+` : 個々のチケットの内容表示画面 50 | 51 | 「Project pattern」は正規表現でプロジェクトの識別子を指定します。v2.7.0にて追加された項目になります。 52 | 「Project pattern」が設定されていた場合、プロジェクトが一致しないと、コードが挿入されません。 53 | 54 | 「Insertion position」は、コードの挿入位置です。v1.2.0にて追加された項目になります。 55 | * 「Head of all pages」 : 全てのページのヘッダ部分。(v1.2.0より前のバージョンと同じ位置) 56 | * 「Bottom of issue form」 : チケットの入力欄の下部。
57 | チケットの入力欄は、トラッカーやステータスを変えると再構成されますが、「Bottom of issue form」を指定しておくと再構成された際に再度実行されるので、入力欄に対する処理はこれを指定すると便利です。 58 | * 「Bottom of issue detail」 : チケットの詳細表示の下部。 59 | * 「Bottom of all pages」 : 全てのページの末尾(HTML body内で一番下の部分)。 60 | * 「Issues context menu」 : チケット一覧のコンテキストメニュー。 61 | 62 | 該当ページにコードの挿入位置に該当する箇所が無かった場合、コードは埋め込まれません。たとえば、「Path pattern」と「Project pattern」の設定が無く、全ページが対象となっても、「Insertion position」に「Bottom of issue detail」を指定していると、チケットの詳細表示画面でしかコードが実行されないことになります。 63 | 64 | 「Type」にてコードの種類(「JavaScript」、「CSS」または「HTML」)を選択し、「Code」に実際のコードを入力します。 65 | 66 | 「Comment」にはカスタマイズに対する概要を記載できます。ここで入力した内容は、一覧表示で表示されます。(Commentが入力されていればComment、Commentが入力されていない場合はCodeが一覧に表示) 67 | 68 | 「Create」ボタン押下で新規カスタマイズの追加が完了です。 69 | 70 | 「Path pattern」と「Project pattern」に一致したページで、「Insertion position」で指定した位置にコードが埋め込まれ、画面がカスタマイズされるようになります。 71 | 72 | ![Screenshot of example](screenshots/example.en.png) 73 | 74 | ### 編集/削除 75 | 76 | ![Screenshot of list edit](screenshots/list_edit.en.png) 77 | 78 | カスタマイズ一覧の番号を押下すると、カスタマイズ詳細画面へ遷移します。 79 | 80 | ![Screenshot of detail](screenshots/detail.en.png) 81 | 82 | 「Delete」を押下すると削除できます。「Edit」を押下すると、編集画面へ遷移します。 83 | 84 | 入力項目は新規カスタマイズ作成時と同じです。 85 | 86 | ### 無効化 / プライベート 87 | 88 | 「Enabled」のチェックを外すと、無効化することができます。「Private」をチェックすると、作成者のみに有効となります。 89 | 90 | ![Screenshot of enabled and private](screenshots/enable_private.en.png) 91 | 92 | まずは「Private」で動作確認したうえで、動作に問題なければ全体に公開するといった使い方ができます。 93 | 94 | ### ViewCustomize.context (JavaScript) 95 | 96 | JavaScriptのコードでは、`ViewCustomize.context`としてユーザやプロジェクトの情報にアクセスすることができます。 97 | 98 | `ViewCustomize.context`の情報は下記のようなイメージです。 99 | 100 | ```javascript 101 | ViewCustomize = { 102 | "context": { 103 | "user": { 104 | "id": 1, 105 | "login": "admin", 106 | "admin": true, 107 | "firstname": "Redmine", 108 | "lastname": "Admin", 109 | "mail": "admin@example.com", 110 | "lastLoginOn": "2019-09-22T14:44:53Z", 111 | "groups": [ 112 | {"id": 5, "name": "Group1"} 113 | ], 114 | "apiKey": "3dd35b5ad8456d90d21ef882f7aea651d367a9d8", 115 | "customFields": [ 116 | {"id": 1, "name": "[Custom field] Text", "value": "text"}, 117 | {"id": 2, "name": "[Custom field] List", "value": ["B", "A"]}, 118 | {"id": 3, "name": "[Custom field] Boolean", "value": "1"} 119 | ] 120 | }, 121 | "project": { 122 | "id": 1, 123 | "identifier": "project-a", 124 | "name": "Project A", 125 | "roles": [ 126 | {"id": 6, "name": "RoleX"} 127 | ], 128 | "customFields": [ 129 | {"id": 4, "name": "[Project Custom field] Text", "value": "text"} 130 | ] 131 | }, 132 | "issue": { 133 | "id": 1, 134 | "author": {"id": 2, "name": "John Smith"}, 135 | "totalEstimatedHours": 10.0, 136 | "totalSpentHours": 11.5, 137 | "lastUpdatedBy": {"id": 1, "name": "Redmine Admin"} 138 | } 139 | } 140 | } 141 | ``` 142 | 143 | 例えばユーザのAPIアクセスキーにアクセスするには`ViewCustomize.context.user.apiKey`となります。 144 | 145 | ### APIアクセスキー 146 | 147 | APIアクセスキーは、個人設定画面のAPIアクセスキーの「表示」リンクを初めて押下したタイミングで生成されます。 148 | 149 | ![Screenshot of my account](screenshots/my_account.en.png) 150 | 151 | 自動的に生成したい場合には、プラグインの設定画面にて「APIアクセスキーを自動的に作成する」をONにしてください。各ユーザに個人設定画面で操作してもらわなくても、APIアクセスキーが生成されるようになります。 152 | 153 | ![Screenshot of plugin configure](screenshots/plugin_configure.en.png) 154 | 155 | APIアクセスキーの利用には、設定画面の「API」タブにて、「RESTによるWebサービスを有効にする」をONにしておく必要があります。 156 | 157 | ## 設定例 158 | 159 | 下記のプロジェクトで設定例を公開しています。 160 | 161 | * [onozaty/redmine\-view\-customize\-scripts: Code examples for "Redmine View Customize Plugin"](https://github.com/onozaty/redmine-view-customize-scripts) 162 | 163 | コードの書き方がわからない場合には、上記プロジェクトを参考にしてみてください。 164 | 165 | 試したコードがうまく動かない場合には、上記プロジェクトの [Issue](https://github.com/onozaty/redmine-view-customize-scripts/issues) から質問することが出来ます。 166 | 質問を受け付ける場所であり、コード作成の依頼場所ではありませんのでご注意ください。 167 | 168 | ## サポートバージョン 169 | 170 | * 最新バージョン : Redmine 3.1.x から 3.4.x、4.0.x 以降 171 | * 1.2.2 : Redmine 2.0.x から 3.4.x 172 | 173 | ## ライセンス 174 | 175 | このプラグインは [GNU General Public License](http://www.gnu.org/licenses/gpl-2.0.html) バージョン2またはそれ以降の条件で利用できます。 176 | 177 | ## 作者 178 | 179 | [onozaty](https://github.com/onozaty) 180 | 181 | もしこのプロジェクトが役に立つと思われましたら、継続的な開発をサポートするために⭐をお願いします。 182 | また、このプロジェクトの維持と持続に貢献してくださる[スポンサー](https://github.com/sponsors/onozaty)を募集しています。 183 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Redmine view customize plugin 2 | 3 | [![CircleCI](https://dl.circleci.com/status-badge/img/gh/onozaty/redmine-view-customize/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/onozaty/redmine-view-customize/tree/master) 4 | 5 | This a plugin allows you to customize the view for the [Redmine](http://www.redmine.org). 6 | 7 | ## Features 8 | 9 | Customize the page by inserting JavaScript, CSS or HTML on the page that matched the condition. 10 | 11 | ## Installation 12 | 13 | Install the plugin in your Redmine plugins directory, clone this repository as `view_customize`: 14 | 15 | ``` 16 | cd {RAILS_ROOT}/plugins 17 | git clone https://github.com/onozaty/redmine-view-customize.git view_customize 18 | cd ../ 19 | bundle install --without development test 20 | bundle exec rake redmine:plugins:migrate RAILS_ENV=production 21 | ``` 22 | 23 | **note: The directory name must be a `view_customize`. Directory name is different, it will fail to run the Plugin.** 24 | 25 | ## Usage 26 | 27 | ### Add 28 | 29 | When installing the plugin, "View customize" is added to the administrator menu. 30 | 31 | ![Screenshot of admin menu](screenshots/admin.en.png) 32 | 33 | Click "View customize" go to the list screen. 34 | 35 | ![Screenshot of list new](screenshots/list_new.en.png) 36 | 37 | Click "New view customize" and enter items. 38 | 39 | ![Screenshot of new](screenshots/new.en.png) 40 | 41 | Use "Path pattern" and "Project pattern" to specify the target page. 42 | If neither is set, all pages will be targeted. 43 | 44 | "Path pattern" is a regular expression to specify the page path. 45 | If a path pattern was set, the code will not be inserted if the path of the page do not match. 46 | 47 | The following is an example. 48 | * `/issues$` : Issue list 49 | * `/issues/[0-9]+` : Issue detail page 50 | 51 | "Project pattern" is a regular expression to specify the project identifier. It becomes item added in v2.7.0. 52 | If the project pattern was set, the code will not be inserted if the current project do not match. 53 | 54 | "Insertion position" is the code insertion position. It becomes item added in v1.2.0. 55 | 56 | * "Head of all pages" (The same position as the version before v1.2.0) 57 | * "Bottom of issue form"
58 | Issue input fields are reconstructed when trackers or statuses are changed. If "Bottom of issue form" is specified, it will be executed again when reconstructed. 59 | * "Bottom of issue detail" 60 | * "Bottom of all pages" (Last in HTML body) 61 | * "Issues context menu" 62 | 63 | If there is no part corresponding to the insertion position of the code on the page, the code is not insert. 64 | For example, even if there are no "Path pattern" and "Project pattern" settings and all pages are targeted, if "Bottom of issue detail" is specified for "Insertion position", it will be executed only on the issue detail page. 65 | 66 | In "Type", select the type of code ("JavaScript", "CSS" or "HTML") and enter the actual code in "Code". 67 | 68 | For "Comment" you can put an overview on customization. The contents entered here are displayed in the list display. 69 | When "Comment" is entered, "Comment" is displayed on the list. 70 | If "Comment" is not entered, "Code" is displayed in the list. 71 | 72 | Addition is completed by clicking "Create" button. 73 | 74 | On the page that matches the "Path pattern" and "Project pattern", the code will be embedded at the position specified in "Insertion position", and the page will be customized. 75 | 76 | ![Screenshot of example](screenshots/example.en.png) 77 | 78 | ### Edit / Delete 79 | 80 | ![Screenshot of list edit](screenshots/list_edit.en.png) 81 | 82 | When you click the number of the customize list, go to the detail page. 83 | 84 | ![Screenshot of detail](screenshots/detail.en.png) 85 | 86 | You can delete it by clicking "Delete". 87 | 88 | Click "Edit" to switch to the edit page. 89 | The input item is the same as when creating a new one. 90 | 91 | ### Disable / Private 92 | 93 | You can disable it by unchecking "Enabled". If you check "Private", it will be enable only for the author. 94 | 95 | ![Screenshot of enabled and private](screenshots/enable_private.en.png) 96 | 97 | If you check the operation with "Private" and there is no problem in operation, it will be good to release it to the all. 98 | 99 | ### ViewCustomize.context (JavaScript) 100 | 101 | You can access information on users and projects using `ViewCustomize.context`. 102 | 103 | `ViewCustomize.context` is as follows. 104 | 105 | ```javascript 106 | ViewCustomize = { 107 | "context": { 108 | "user": { 109 | "id": 1, 110 | "login": "admin", 111 | "admin": true, 112 | "firstname": "Redmine", 113 | "lastname": "Admin", 114 | "mail": "admin@example.com", 115 | "lastLoginOn": "2019-09-22T14:44:53Z", 116 | "groups": [ 117 | {"id": 5, "name": "Group1"} 118 | ], 119 | "apiKey": "3dd35b5ad8456d90d21ef882f7aea651d367a9d8", 120 | "customFields": [ 121 | {"id": 1, "name": "[Custom field] Text", "value": "text"}, 122 | {"id": 2, "name": "[Custom field] List", "value": ["B", "A"]}, 123 | {"id": 3, "name": "[Custom field] Boolean", "value": "1"} 124 | ] 125 | }, 126 | "project": { 127 | "id": 1, 128 | "identifier": "project-a", 129 | "name": "Project A", 130 | "roles": [ 131 | {"id": 6, "name": "RoleX"} 132 | ], 133 | "customFields": [ 134 | {"id": 4, "name": "[Project Custom field] Text", "value": "text"} 135 | ] 136 | }, 137 | "issue": { 138 | "id": 1, 139 | "author": {"id": 2, "name": "John Smith"}, 140 | "totalEstimatedHours": 10.0, 141 | "totalSpentHours": 11.5, 142 | "lastUpdatedBy": {"id": 1, "name": "Redmine Admin"} 143 | } 144 | } 145 | } 146 | ``` 147 | 148 | For example, to access the user's API access key is `ViewCustomize.context.user.apiKey`. 149 | 150 | ### API access key 151 | 152 | The API access key is created when the "Show" link of the API access key on the My account page is click for the first time. 153 | 154 | ![Screenshot of my account](screenshots/my_account.en.png) 155 | 156 | If you want to created it automatically, set "Automatically create API access key" to ON in the plugin configure page. API access keys can be created without having each user operate the My account page. 157 | 158 | ![Screenshot of plugin configure](screenshots/plugin_configure.en.png) 159 | 160 | To use the API access key, "Enable REST web service" must be turned on in the "API" tab of the setting page. 161 | 162 | ## Examples 163 | 164 | Example code is published in the following project. 165 | 166 | * [onozaty/redmine\-view\-customize\-scripts: Code examples for "Redmine View Customize Plugin"](https://github.com/onozaty/redmine-view-customize-scripts) 167 | 168 | If you don't know how to write the code, please refer to the project above. 169 | 170 | If the code you try does not work, you can ask questions from the [Issue](https://github.com/onozaty/redmine-view-customize-scripts/issues) of the above project. 171 | Please note that this is a place to ask questions, not a place to request coding. 172 | 173 | ## Supported versions 174 | 175 | * Current version : Redmine 3.1.x - 3.4.x, 4.0.x or later 176 | * 1.2.2 : Redmine 2.0.x - 3.4.x 177 | 178 | ## License 179 | 180 | The plugin is available under the terms of the [GNU General Public License](http://www.gnu.org/licenses/gpl-2.0.html), version 2 or later. 181 | 182 | ## Author 183 | 184 | [onozaty](https://github.com/onozaty) 185 | 186 | If you find this project useful, please ⭐ it to support its ongoing development. 187 | I am also looking for [sponsors](https://github.com/sponsors/onozaty) who are interested in contributing to the maintenance and sustainability of this project. Your support would be highly appreciated. 188 | -------------------------------------------------------------------------------- /after_init.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../lib/redmine_view_customize/view_hook', __FILE__) 2 | -------------------------------------------------------------------------------- /app/controllers/view_customizes_controller.rb: -------------------------------------------------------------------------------- 1 | class ViewCustomizesController < ApplicationController 2 | layout 'admin' 3 | 4 | before_action :require_admin 5 | before_action :find_view_customize, :except => [:index, :new, :create, :update_all] 6 | 7 | helper :sort 8 | include SortHelper 9 | 10 | def index 11 | sort_init 'id', 'desc' 12 | sort_update %w(id path_pattern insertion_position customize_type code comments is_enabled is_private) 13 | @view_customizes = ViewCustomize.order(sort_clause) 14 | end 15 | 16 | def new 17 | @view_customize = ViewCustomize.new 18 | end 19 | 20 | def create 21 | @view_customize = ViewCustomize.new(view_customize_params) 22 | 23 | if @view_customize.save 24 | flash[:notice] = l(:notice_successful_create) 25 | redirect_to view_customize_path(@view_customize.id) 26 | else 27 | render :action => 'new' 28 | end 29 | end 30 | 31 | def show 32 | end 33 | 34 | def edit 35 | end 36 | 37 | def update 38 | @view_customize.attributes = view_customize_params 39 | if @view_customize.save 40 | flash[:notice] = l(:notice_successful_update) 41 | redirect_to view_customize_path(@view_customize.id) 42 | else 43 | render :action => 'edit' 44 | end 45 | rescue ActiveRecord::StaleObjectError 46 | flash.now[:error] = l(:notice_locking_conflict) 47 | render :action => 'edit' 48 | end 49 | 50 | def update_all 51 | ViewCustomize.update_all(view_customize_params.to_hash) 52 | 53 | flash[:notice] = l(:notice_successful_update) 54 | redirect_to view_customizes_path 55 | end 56 | 57 | def destroy 58 | @view_customize.destroy 59 | redirect_to view_customizes_path 60 | end 61 | 62 | private 63 | 64 | def find_view_customize 65 | @view_customize = ViewCustomize.find(params[:id]) 66 | render_404 unless @view_customize 67 | end 68 | 69 | def view_customize_params 70 | params.require(:view_customize) 71 | .permit(:path_pattern, :project_pattern, :customize_type, :code, :is_enabled, :is_private, :insertion_position, :comments) 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /app/helpers/view_customizes_helper.rb: -------------------------------------------------------------------------------- 1 | module ViewCustomizesHelper 2 | def highlight_by_language(code, language) 3 | code.gsub!(/(\r\n|\r|\n)/, "\n") 4 | ("
" +
5 |          Redmine::SyntaxHighlighting.highlight_by_language(code, language) +
6 |          "
").html_safe 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /app/models/view_customize.rb: -------------------------------------------------------------------------------- 1 | class ViewCustomize < (defined?(ApplicationRecord) == 'constant' ? ApplicationRecord : ActiveRecord::Base) 2 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' 3 | 4 | validates_length_of :path_pattern, :maximum => 255 5 | validates_length_of :project_pattern, :maximum => 255 6 | 7 | validates_presence_of :code 8 | 9 | validate :valid_pattern 10 | 11 | TYPE_JAVASCRIPT = "javascript" 12 | TYPE_CSS = "css" 13 | TYPE_HTML = "html" 14 | 15 | @@customize_types = { 16 | :label_javascript => TYPE_JAVASCRIPT, 17 | :label_css => TYPE_CSS, 18 | :label_html => TYPE_HTML 19 | } 20 | 21 | INSERTION_POSITION_HTML_HEAD = "html_head" 22 | INSERTION_POSITION_HTML_BOTTOM = "html_bottom" 23 | INSERTION_POSITION_ISSUE_FORM = "issue_form" 24 | INSERTION_POSITION_ISSUE_SHOW = "issue_show" 25 | INSERTION_POSITION_ISSUES_CONTEXT_MENU = "issues_context_menu" 26 | 27 | @@insertion_positions = { 28 | :label_insertion_position_html_head => INSERTION_POSITION_HTML_HEAD, 29 | :label_insertion_position_issue_form => INSERTION_POSITION_ISSUE_FORM, 30 | :label_insertion_position_issue_show => INSERTION_POSITION_ISSUE_SHOW, 31 | :label_insertion_position_html_bottom => INSERTION_POSITION_HTML_BOTTOM, 32 | :label_insertion_position_issues_context_menu => INSERTION_POSITION_ISSUES_CONTEXT_MENU 33 | } 34 | 35 | def customize_types 36 | @@customize_types 37 | end 38 | 39 | def customize_type_label 40 | @@customize_types.key(customize_type) 41 | end 42 | 43 | def insertion_positions 44 | @@insertion_positions 45 | end 46 | 47 | def insertion_position_label 48 | @@insertion_positions.key(insertion_position) 49 | end 50 | 51 | def is_javascript? 52 | customize_type == TYPE_JAVASCRIPT 53 | end 54 | 55 | def is_css? 56 | customize_type == TYPE_CSS 57 | end 58 | 59 | def is_html? 60 | customize_type == TYPE_HTML 61 | end 62 | 63 | def available?(user=User.current) 64 | is_enabled && (!is_private || author == user) 65 | end 66 | 67 | def valid_pattern 68 | if path_pattern.present? 69 | begin 70 | Regexp.compile(path_pattern) 71 | rescue 72 | errors.add(:path_pattern, :invalid) 73 | end 74 | end 75 | 76 | if project_pattern.present? 77 | begin 78 | Regexp.compile(project_pattern) 79 | rescue 80 | errors.add(:project_pattern, :invalid) 81 | end 82 | end 83 | 84 | end 85 | 86 | def initialize(attributes=nil, *args) 87 | super 88 | if new_record? 89 | self.author = User.current 90 | end 91 | end 92 | 93 | end 94 | -------------------------------------------------------------------------------- /app/views/settings/_view_customize_settings.html.erb: -------------------------------------------------------------------------------- 1 |

2 | 3 | <%= hidden_field_tag 'settings[create_api_access_key]', '0' %> 4 | <%= check_box_tag 'settings[create_api_access_key]', '1', @settings[:create_api_access_key] == '1' %> 5 |

6 | -------------------------------------------------------------------------------- /app/views/view_customizes/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= error_messages_for 'view_customize' %> 2 |
3 |

4 | <%= form.text_field :path_pattern, 5 | :size => 100 %> 6 | 7 | <%= l(:text_path_pattern_info) %>
8 | <%= l(:text_path_pattern_match_info) %> 9 |
10 |

11 |

12 | <%= form.text_field :project_pattern, 13 | :size => 100 %> 14 | 15 | <%= l(:text_project_pattern_info) %>
16 | <%= l(:text_project_pattern_match_info) %> 17 |
18 |

19 |

20 | <%= form.select :insertion_position, 21 | options_for_select( 22 | @view_customize.insertion_positions.map {|key, val| [l(key), val]}, 23 | :selected => @view_customize.insertion_position), 24 | :required => true %> 25 |

26 |

27 | <%= form.select :customize_type, 28 | options_for_select( 29 | @view_customize.customize_types.map {|key, val| [l(key), val]}, 30 | :selected => @view_customize.customize_type), 31 | :required => true %> 32 |

33 |

34 | <%= form.text_area :code, 35 | :required => true, :rows => 12 %> 36 |

37 |

38 | <%= form.text_field :comments, :size => 100 %> 39 |

40 |

41 | <%= form.check_box :is_enabled %> 42 |

43 |

44 | <%= form.check_box :is_private %> 45 |

46 |
47 | -------------------------------------------------------------------------------- /app/views/view_customizes/edit.html.erb: -------------------------------------------------------------------------------- 1 | <%= title [l(:label_view_customize_plural), view_customizes_path], @view_customize.id %> 2 | 3 | <%= labelled_form_for :view_customize, @view_customize, 4 | :url => view_customize_path, 5 | :html => {:multipart => true, :id => 'view_customize-form'} do |f| %> 6 | <%= render :partial => 'view_customizes/form', :locals => {:form => f} %> 7 | <%= f.submit l(:button_save) %> 8 | <%= link_to l(:button_cancel), :controller => 'view_customizes', :action => 'show', :id => @view_customize.id %> 9 | <% end %> 10 | -------------------------------------------------------------------------------- /app/views/view_customizes/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <%= link_to l(:label_view_customizes_new), 3 | new_view_customize_path, :class => 'icon icon-add' %> 4 |
5 | 6 | <%= title l(:label_view_customize_plural) %> 7 | 8 | <% if (@view_customizes.blank?) %> 9 |

<%= l(:label_no_data) %>

10 | <% else %> 11 | 12 | 13 | 14 | 15 | 16 | <%= sort_header_tag('id', :caption => '#') %> 17 | <%= sort_header_tag('path_pattern', :caption => l(:field_path_pattern)) %> 18 | <%= sort_header_tag('project_pattern', :caption => l(:field_project_pattern)) %> 19 | <%= sort_header_tag('insertion_position', :caption => l(:field_insertion_position)) %> 20 | <%= sort_header_tag('customize_type', :caption => l(:field_customize_type)) %> 21 | <%= sort_header_tag('comments', :caption => l(:field_comments) + ' / ' + l(:field_code)) %> 22 | <%= sort_header_tag('is_private', :caption => l(:field_is_private)) %> 23 | 24 | 25 | 26 | 27 | <% @view_customizes.each do |view_customize| %> 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | <% end %> 38 | 39 | 40 |
<%= link_to view_customize.id, view_customize_path(view_customize.id) %><%=h view_customize.path_pattern %><%=h view_customize.project_pattern%><%=h l(view_customize.insertion_position_label) %><%=h l(view_customize.customize_type_label) %><%=h view_customize.comments.present? ? view_customize.comments : truncate(view_customize.code, :length => 80) %><%=h view_customize.is_private ? l(:general_text_yes) : l(:general_text_no) %>
41 | 42 |

43 | <%= link_to l(:label_disable_all), 44 | view_customizes_path(view_customize: {is_enabled: 0}), 45 | :data => {:confirm => l(:text_are_you_sure)}, :method => :put, 46 | :class => 'icon icon-view_customize-disable' %> 47 | <%= link_to l(:label_enable_all), 48 | view_customizes_path(view_customize: {is_enabled: 1}), 49 | :data => {:confirm => l(:text_are_you_sure)}, :method => :put, 50 | :class => 'icon icon-view_customize-enable' %> 51 |

52 | <% end %> 53 | -------------------------------------------------------------------------------- /app/views/view_customizes/new.html.erb: -------------------------------------------------------------------------------- 1 | <%= title [l(:label_view_customize_plural), view_customizes_path], l(:label_view_customizes_new) %> 2 | 3 | <%= labelled_form_for :view_customize, @view_customize, 4 | :url => view_customizes_path, 5 | :html => {:multipart => true, :id => 'view_customize-form'} do |f| %> 6 | <%= render :partial => 'view_customizes/form', :locals => {:form => f} %> 7 | <%= f.submit l(:button_create) %> 8 | <%= link_to l(:button_cancel), :controller => 'view_customizes', :action => 'index' %> 9 | <% end %> 10 | -------------------------------------------------------------------------------- /app/views/view_customizes/show.html.erb: -------------------------------------------------------------------------------- 1 | <%= stylesheet_link_tag "scm" %> 2 | 3 |
4 | <%= link_to(l(:button_edit), 5 | {:action => 'edit', :id => @view_customize.id}, 6 | :class => 'icon icon-edit') %> 7 | <%= link_to(l(:button_delete), 8 | {:action => 'destroy', :id => @view_customize.id}, 9 | :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, 10 | :class => 'icon icon-del') %> 11 |
12 | 13 | <%= title [l(:label_view_customize_plural), view_customizes_path], @view_customize.id %> 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
<%=h l(:field_path_pattern) %><%=h @view_customize.path_pattern %>
<%=h l(:field_project_pattern) %><%=h @view_customize.project_pattern %>
<%=h l(:field_insertion_position) %><%=h l(@view_customize.insertion_position_label) %>
<%=h l(:field_customize_type) %><%=h l(@view_customize.customize_type_label) %>
<%=h l(:field_code) %>
<%= highlight_by_language( 35 | @view_customize.code, @view_customize.customize_type.to_sym) %>
<%=h l(:field_comments) %><%=h @view_customize.comments %>
<%=h l(:field_is_enabled) %><%=h @view_customize.is_enabled ? l(:general_text_yes) : l(:general_text_no) %>
<%=h l(:field_is_private) %><%=h @view_customize.is_private ? l(:general_text_yes) : l(:general_text_no) %>
<%=h l(:field_author) %><%=h @view_customize.author.name unless @view_customize.author == nil %>
54 | -------------------------------------------------------------------------------- /assets/images/disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/assets/images/disable.png -------------------------------------------------------------------------------- /assets/images/enable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/assets/images/enable.png -------------------------------------------------------------------------------- /assets/images/view_customize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/assets/images/view_customize.png -------------------------------------------------------------------------------- /assets/stylesheets/view_customize.css: -------------------------------------------------------------------------------- 1 | table.view_customize.list td.path, table.view_customize.list td.comments { 2 | text-align: left; 3 | word-break: break-word; 4 | overflow-wrap: break-word; 5 | word-wrap : break-word; 6 | } 7 | 8 | table.view_customize.list td.id { 9 | padding-left: 5px; 10 | } 11 | 12 | table.view_customize.list td.insertion_position { 13 | white-space: nowrap; 14 | } 15 | 16 | table.view_customize.list tr.disable { 17 | color: #aaaaaa; 18 | } 19 | 20 | table.view_customize.list tr.private { 21 | font-style: italic; 22 | } 23 | 24 | table.view_customize.box { 25 | width: 100%; 26 | table-layout: fixed; 27 | } 28 | 29 | table.view_customize.box th { 30 | text-align: right; 31 | vertical-align: top; 32 | width: 160px; 33 | padding: 2px 10px 2px 0px; 34 | } 35 | 36 | table.view_customize.box td { 37 | vertical-align: top; 38 | padding: 2px; 39 | } 40 | 41 | table.view_customize.box td pre { 42 | margin: 0; 43 | padding: 2px 4px; 44 | background-color: #fafafa; 45 | border: 1px solid #e2e2e2; 46 | border-radius: 3px; 47 | width: auto; 48 | overflow-x: auto; 49 | overflow-y: hidden; 50 | } 51 | 52 | textarea#view_customize_code { 53 | resize: vertical; 54 | width: 95%; 55 | } 56 | 57 | input#view_customize_comments { 58 | width: 95%; 59 | } 60 | 61 | .icon-view_customize { 62 | background-image: url("../images/view_customize.png"); 63 | } 64 | 65 | .icon-view_customize-disable { 66 | background-image: url("../images/disable.png"); 67 | } 68 | 69 | .icon-view_customize-enable { 70 | background-image: url("../images/enable.png"); 71 | } 72 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | en: 2 | label_view_customize: "View customize" 3 | label_view_customize_plural: "View customizes" 4 | label_view_customizes_new: "New view customize" 5 | label_disable_all: "Disable all" 6 | label_enable_all: "Enable all" 7 | label_javascript: "JavaScript" 8 | label_css: "CSS" 9 | label_html: "HTML" 10 | label_insertion_position_html_head: "Head of all pages" 11 | label_insertion_position_html_bottom: "Bottom of all pages" 12 | label_insertion_position_issue_form: "Bottom of issue form" 13 | label_insertion_position_issue_show: "Bottom of issue detail" 14 | label_insertion_position_issues_context_menu: "Issues context menu" 15 | field_path_pattern: "Path pattern" 16 | field_project_pattern: "Project pattern" 17 | field_insertion_position: "Insertion position" 18 | field_customize_type: "Type" 19 | field_code: "Code" 20 | field_comments: "Comment" 21 | field_is_private: "Private" 22 | field_is_enabled: "Enabled" 23 | field_author: "Author" 24 | text_path_pattern_info: "Path pattern is specified with a regular expression. (ex. /issues/[0-9]+)" 25 | text_path_pattern_match_info: "If a path pattern was set, the code will not be inserted if the path of the page do not match." 26 | text_project_pattern_info: "Project (identifier) pattern is specified with a regular expression. (ex. sample-proj-a|sample-proj-b)" 27 | text_project_pattern_match_info: "If the project pattern was set, the code will not be inserted if the current project do not match." 28 | option_create_api_access_key: "Automatically create API access key" 29 | -------------------------------------------------------------------------------- /config/locales/ja.yml: -------------------------------------------------------------------------------- 1 | ja: 2 | label_view_customize: "表示のカスタマイズ" 3 | label_view_customize_plural: "表示のカスタマイズ" 4 | label_view_customizes_new: "新しい表示のカスタマイズ" 5 | label_disable_all: "すべて無効に" 6 | label_enable_all: "すべて有効に" 7 | label_javascript: "JavaScript" 8 | label_css: "CSS" 9 | label_html: "HTML" 10 | label_insertion_position_html_head: "全ページのヘッダ" 11 | label_insertion_position_html_bottom: "全ページの末尾" 12 | label_insertion_position_issue_form: "チケット入力欄の下" 13 | label_insertion_position_issue_show: "チケット詳細の下" 14 | label_insertion_position_issues_context_menu: "チケット一覧のコンテキストメニュー" 15 | field_path_pattern: "パスのパターン" 16 | field_project_pattern: "プロジェクトのパターン" 17 | field_insertion_position: "挿入位置" 18 | field_customize_type: "種別" 19 | field_code: "コード" 20 | field_comments: "コメント" 21 | field_is_private: "プライベート" 22 | field_is_enabled: "有効" 23 | field_author: "作成者" 24 | text_path_pattern_info: "パスを正規表現で指定します。(例 /issues/[0-9]+)" 25 | text_path_pattern_match_info: "パスのパターンが設定されていた場合、ページのパスが一致しないと、コードが挿入されません。" 26 | text_project_pattern_info: "プロジェクト(識別子)を正規表現で指定します。 (例 sample-proj-a|sample-proj-b)" 27 | text_project_pattern_match_info: "プロジェクトのパターンが設定されていた場合、プロジェクトが一致しないと、コードが挿入されません。" 28 | option_create_api_access_key: "APIアクセスキーを自動的に作成する" 29 | -------------------------------------------------------------------------------- /config/locales/zh-TW.yml: -------------------------------------------------------------------------------- 1 | zh-TW: 2 | label_view_customize: "自訂視圖" 3 | label_view_customize_plural: "自訂視圖清單" 4 | label_view_customizes_new: "新建自訂視圖" 5 | label_disable_all: "禁用全部" 6 | label_enable_all: "啟用全部" 7 | label_javascript: "JavaScript" 8 | label_css: "CSS" 9 | label_html: "HTML" 10 | label_insertion_position_html_head: "所有頁面的頂部" 11 | label_insertion_position_html_bottom: "所有頁面的底部" 12 | label_insertion_position_issue_form: "議題清單底部" 13 | label_insertion_position_issue_show: "議題詳情頁面" 14 | label_insertion_position_issues_context_menu: "議題上下文菜單" 15 | field_path_pattern: "路徑表達式" 16 | field_project_pattern: "專案表達式" 17 | field_insertion_position: "嵌入位置" 18 | field_customize_type: "類別" 19 | field_code: "程式碼" 20 | field_comments: "注釋" 21 | field_is_private: "私有" 22 | field_is_enabled: "啟用" 23 | field_author: "作者" 24 | text_path_pattern_info: "路徑表達式使用正則表達式指定。(例如 /issues/[0-9]+)" 25 | text_path_pattern_match_info: "如果設置了路徑表達式,則如果頁面的路徑不匹配,則不會插入程式碼。" 26 | text_project_pattern_info: "專案代碼表達式使用正則表達式指定。 (例如 sample-proj-a|sample-proj-b)" 27 | text_project_pattern_match_info: "如果設置了專案表達式,則如果當前專案不匹配,則不會插入程式碼。" 28 | option_create_api_access_key: "自動創建API金鑰(API access key)" 29 | -------------------------------------------------------------------------------- /config/locales/zh.yml: -------------------------------------------------------------------------------- 1 | zh: 2 | label_view_customize: "自定义视图" 3 | label_view_customize_plural: "自定义视图" 4 | label_view_customizes_new: "新建自定义视图" 5 | label_disable_all: "禁用全部" 6 | label_enable_all: "启用全部" 7 | label_javascript: "JavaScript" 8 | label_css: "CSS" 9 | label_html: "HTML" 10 | label_insertion_position_html_head: "所有页面的头部" 11 | label_insertion_position_html_bottom: "所有页面的底部" 12 | label_insertion_position_issue_form: "问题(issue)表单底部" 13 | label_insertion_position_issue_show: "问题(issue)详情页面" 14 | label_insertion_position_issues_context_menu: "问题(issue)上下文菜单" 15 | field_path_pattern: "路径表达式" 16 | field_project_pattern: "项目表达式" 17 | field_insertion_position: "嵌入位置" 18 | field_customize_type: "类别" 19 | field_code: "代码" 20 | field_comments: "注释" 21 | field_is_private: "私有" 22 | field_is_enabled: "启用" 23 | field_author: "作者" 24 | text_path_pattern_info: "路径表达式使用正则表达式指定。(例如 /issues/[0-9]+)" 25 | text_path_pattern_match_info: "如果设置了路径表达式,则如果页面的路径不匹配,则不会插入代码。" 26 | text_project_pattern_info: "项目(标识符)表达式使用正则表达式指定。 (例如 sample-proj-a|sample-proj-b)" 27 | text_project_pattern_match_info: "如果设置了项目表达式,则如果当前项目不匹配,则不会插入代码。" 28 | option_create_api_access_key: "自动创建API密钥(API access key)" 29 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | # Plugin's routes 2 | # See: http://guides.rubyonrails.org/routing.html 3 | Rails.application.routes.draw do 4 | resources :view_customizes 5 | put :view_customizes, to: 'view_customizes#update_all' 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/001_create_view_customizes.rb: -------------------------------------------------------------------------------- 1 | class CreateViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class 2 | def change 3 | create_table :view_customizes do |t| 4 | t.string :path_pattern 5 | t.integer :customize_type 6 | t.text :code 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/002_add_column_view_customizes.rb: -------------------------------------------------------------------------------- 1 | class AddColumnViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class 2 | def up 3 | add_column :view_customizes, :is_enabled, :boolean, :null => false, :default => true 4 | add_column :view_customizes, :is_private, :boolean, :null => false, :default => false 5 | add_column :view_customizes, :author_id, :integer, :null => false, :default => 0 6 | end 7 | 8 | def down 9 | remove_column :view_customizes, :is_enabled 10 | remove_column :view_customizes, :is_private 11 | remove_column :view_customizes, :author_id 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /db/migrate/003_add_insertion_position_to_view_customizes.rb: -------------------------------------------------------------------------------- 1 | class AddInsertionPositionToViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class 2 | def up 3 | add_column :view_customizes, :insertion_position, :string, :null => false, :default => "html_head" 4 | 5 | rename_column :view_customizes, :customize_type, :customize_type_old 6 | add_column :view_customizes, :customize_type, :string, :null => false, :default => "javascript" 7 | ActiveRecord::Base.connection.execute( 8 | "UPDATE view_customizes SET customize_type = 'css' WHERE customize_type_old = 2") 9 | remove_column :view_customizes, :customize_type_old 10 | 11 | change_column_null :view_customizes, :path_pattern, false 12 | change_column_null :view_customizes, :code, false 13 | end 14 | 15 | def down 16 | change_column_null :view_customizes, :path_pattern, true 17 | change_column_null :view_customizes, :code, true 18 | 19 | rename_column :view_customizes, :customize_type, :customize_type_new 20 | add_column :view_customizes, :customize_type, :integer, :default => 1 21 | ActiveRecord::Base.connection.execute( 22 | "UPDATE view_customizes SET customize_type = 1 WHERE customize_type_new = 'css'") 23 | remove_column :view_customizes, :customize_type_new 24 | 25 | remove_column :view_customizes, :insertion_position 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /db/migrate/004_add_comments_to_view_customizes.rb: -------------------------------------------------------------------------------- 1 | class AddCommentsToViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class 2 | def up 3 | add_column :view_customizes, :comments, :string, :null => true 4 | end 5 | 6 | def down 7 | remove_column :view_customizes, :comments 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/005_change_code_limit_on_view_customizes.rb: -------------------------------------------------------------------------------- 1 | class ChangeCodeLimitOnViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class 2 | def up 3 | change_column :view_customizes, :code, :text, :limit => 16.megabytes 4 | end 5 | 6 | def down 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/migrate/006_add_project_pattern_to_view_customizes.rb: -------------------------------------------------------------------------------- 1 | class AddProjectPatternToViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class 2 | def up 3 | add_column :view_customizes, :project_pattern, :string, :null => false, :default => "" 4 | end 5 | 6 | def down 7 | remove_column :view_customizes, :project_pattern 8 | end 9 | end 10 | 11 | 12 | -------------------------------------------------------------------------------- /db/migrate/007_change_path_pattern_default_on_view_customizes.rb: -------------------------------------------------------------------------------- 1 | class ChangePathPatternDefaultOnViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class 2 | def change 3 | change_column_default :view_customizes, :path_pattern, from: nil, to: "" 4 | change_column_default :view_customizes, :comments, from: nil, to: "" 5 | change_column_null :view_customizes, :comments, false, "" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /db/migrate/008_change_default_bugfix_on_view_customizes.rb: -------------------------------------------------------------------------------- 1 | class ChangeDefaultBugfixOnViewCustomizes < ActiveRecord::CompatibleLegacyMigration.migration_class 2 | def up 3 | change_column_default :view_customizes, :path_pattern, "" 4 | change_column_default :view_customizes, :comments, "" 5 | end 6 | 7 | def down 8 | # Leave the default values unchanged 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | Redmine::Plugin.register :view_customize do 2 | requires_redmine :version_or_higher => '3.1.0' 3 | name 'View Customize plugin' 4 | author 'onozaty' 5 | description 'View Customize plugin for Redmine' 6 | version '3.5.2' 7 | url 'https://github.com/onozaty/redmine-view-customize' 8 | author_url 'https://github.com/onozaty' 9 | 10 | menu :admin_menu, :view_customizes, 11 | { :controller => 'view_customizes', :action => 'index' }, 12 | :caption => :label_view_customize, 13 | :html => { :class => 'icon icon-view_customize'}, 14 | :if => Proc.new { User.current.admin? } 15 | 16 | settings :default => { 'create_api_access_key' => '' }, :partial => 'settings/view_customize_settings' 17 | 18 | should_be_disabled false if Redmine::Plugin.installed?(:easy_extensions) 19 | end 20 | 21 | unless Redmine::Plugin.installed?(:easy_extensions) 22 | require_relative 'after_init' 23 | end 24 | -------------------------------------------------------------------------------- /lib/redmine_view_customize/view_hook.rb: -------------------------------------------------------------------------------- 1 | require 'time' 2 | 3 | module RedmineViewCustomize 4 | class ViewHook < Redmine::Hook::ViewListener 5 | def view_layouts_base_html_head(context={}) 6 | path = sanitize(Redmine::CodesetUtil.replace_invalid_utf8(context[:request].path_info)); 7 | 8 | html = "\n\n" 9 | html << stylesheet_link_tag("view_customize", plugin: "view_customize") 10 | html << "\n" 13 | 14 | html << create_view_customize_html(context, ViewCustomize::INSERTION_POSITION_HTML_HEAD) 15 | 16 | return html 17 | end 18 | 19 | def view_layouts_base_body_bottom(context={}) 20 | return "\n" + create_view_customize_html(context, ViewCustomize::INSERTION_POSITION_HTML_BOTTOM) 21 | end 22 | 23 | def view_issues_form_details_bottom(context={}) 24 | 25 | return "\n" + create_view_customize_html(context, ViewCustomize::INSERTION_POSITION_ISSUE_FORM) 26 | end 27 | 28 | def view_issues_show_details_bottom(context={}) 29 | 30 | issue = { 31 | "id" => context[:issue].id, 32 | "author" => { 33 | "id" => context[:issue].author.id, 34 | "name" => context[:issue].author.name 35 | }, 36 | "totalEstimatedHours" => context[:issue].total_estimated_hours, 37 | "totalSpentHours" => context[:issue].total_spent_hours 38 | } 39 | 40 | if context[:issue].last_updated_by.present? 41 | issue["lastUpdatedBy"] = { 42 | "id" => context[:issue].last_updated_by.id, 43 | "name" => context[:issue].last_updated_by.name 44 | } 45 | end 46 | 47 | html = "\n\n" 50 | 51 | html << create_view_customize_html(context, ViewCustomize::INSERTION_POSITION_ISSUE_SHOW) 52 | 53 | return html 54 | end 55 | 56 | def view_issues_context_menu_end(context={}) 57 | return "\n" + create_view_customize_html(context, ViewCustomize::INSERTION_POSITION_ISSUES_CONTEXT_MENU) 58 | end 59 | 60 | private 61 | 62 | def create_view_customize_html(context, insertion_position) 63 | 64 | view_customize_html_parts = match_customize(context, insertion_position).map {|item| 65 | to_html(item) 66 | } 67 | return view_customize_html_parts.join("\n").html_safe + "\n" 68 | 69 | end 70 | 71 | def match_customize(context, insertion_position) 72 | path = Redmine::CodesetUtil.replace_invalid_utf8(context[:request].path_info) 73 | project = context[:project].identifier if context[:project] 74 | 75 | ViewCustomize.all.order(:id).select {|item| target_customize?(path, project, insertion_position, item)} 76 | end 77 | 78 | def target_customize?(path, project, insertion_position, item) 79 | return false unless item.available? 80 | return false unless item.insertion_position == insertion_position 81 | 82 | if item.path_pattern.present? 83 | return false unless path =~ Regexp.new(item.path_pattern) 84 | end 85 | 86 | if item.project_pattern.present? 87 | return false unless project.present? 88 | return false unless project =~ Regexp.new(item.project_pattern) 89 | end 90 | 91 | return true 92 | end 93 | 94 | def to_html(view_customize) 95 | 96 | html = "\n" 97 | 98 | if view_customize.is_javascript? 99 | html << "" 102 | elsif view_customize.is_css? 103 | html << "" 106 | elsif view_customize.is_html? 107 | html << view_customize.code 108 | end 109 | 110 | return html 111 | end 112 | 113 | def create_view_customize_context(view_hook_context) 114 | 115 | user = User.current 116 | 117 | if Setting.plugin_view_customize[:create_api_access_key] == "1" and user.api_token.nil? 118 | # Create API access key 119 | user.api_key 120 | end 121 | 122 | context = { 123 | "user" => { 124 | "id" => user.id, 125 | "login" => user.login, 126 | "admin" => user.admin?, 127 | "firstname" => user.firstname, 128 | "lastname" => user.lastname, 129 | "mail" => user.mail, 130 | "lastLoginOn" => (user.last_login_on.iso8601 unless user.last_login_on.nil?), 131 | "groups" => user.groups.map {|group| { "id" => group.id, "name" => group.name }}, 132 | "apiKey" => (user.api_token.value unless user.api_token.nil?), 133 | "customFields" => user.custom_field_values.map {|field| { "id" => field.custom_field.id, "name" => field.custom_field.name, "value" => field.value }} 134 | } 135 | } 136 | 137 | project = view_hook_context[:project] 138 | if project 139 | context["project"] = { 140 | "id" => project.id, 141 | "identifier" => project.identifier, 142 | "name" => project.name, 143 | "roles" => user.roles_for_project(project).map {|role| { "id" => role.id, "name" => role.name }}, 144 | # Only include custom field values which are visible to the current user 145 | "customFields" => project.visible_custom_field_values().map {|field| { "id" => field.custom_field.id, "name" => field.custom_field.name, "value" => field.value }} 146 | } 147 | end 148 | 149 | return context 150 | end 151 | end 152 | end 153 | -------------------------------------------------------------------------------- /screenshots/admin.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/screenshots/admin.en.png -------------------------------------------------------------------------------- /screenshots/detail.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/screenshots/detail.en.png -------------------------------------------------------------------------------- /screenshots/enable_private.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/screenshots/enable_private.en.png -------------------------------------------------------------------------------- /screenshots/example.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/screenshots/example.en.png -------------------------------------------------------------------------------- /screenshots/list_edit.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/screenshots/list_edit.en.png -------------------------------------------------------------------------------- /screenshots/list_new.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/screenshots/list_new.en.png -------------------------------------------------------------------------------- /screenshots/my_account.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/screenshots/my_account.en.png -------------------------------------------------------------------------------- /screenshots/new.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/screenshots/new.en.png -------------------------------------------------------------------------------- /screenshots/plugin_configure.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onozaty/redmine-view-customize/2bb5cdc42d9fd2b6544fda1db630a242f5a0d5b3/screenshots/plugin_configure.en.png -------------------------------------------------------------------------------- /test/fixtures/view_customizes.yml: -------------------------------------------------------------------------------- 1 | view_customize_001: 2 | id: 1 3 | path_pattern: /issues$ 4 | code: code_001 5 | is_enabled: true 6 | is_private: false 7 | author_id: 1 8 | insertion_position: html_head 9 | customize_type: javascript 10 | comments: comment_001 11 | project_pattern: "" 12 | view_customize_002: 13 | id: 2 14 | path_pattern: "" 15 | code: code_002 16 | is_enabled: true 17 | is_private: false 18 | author_id: 1 19 | insertion_position: html_head 20 | customize_type: css 21 | comments: "" 22 | project_pattern: "" 23 | view_customize_003: 24 | id: 3 25 | path_pattern: "" 26 | code: code_003 27 | is_enabled: true 28 | is_private: false 29 | author_id: 1 30 | insertion_position: html_head 31 | customize_type: html 32 | comments: "" 33 | project_pattern: ecookbook 34 | view_customize_004: 35 | id: 4 36 | path_pattern: /issues/new 37 | code: code_004 38 | is_enabled: true 39 | is_private: false 40 | author_id: 1 41 | insertion_position: html_head 42 | customize_type: html 43 | comments: "" 44 | project_pattern: ecookbook 45 | view_customize_005: 46 | id: 5 47 | path_pattern: "" 48 | code: code_005 49 | is_enabled: false 50 | is_private: false 51 | author_id: 1 52 | insertion_position: html_head 53 | customize_type: javascript 54 | comments: "" 55 | project_pattern: "" 56 | view_customize_006: 57 | id: 6 58 | path_pattern: "" 59 | code: code_006 60 | is_enabled: true 61 | is_private: true 62 | author_id: 2 63 | insertion_position: html_head 64 | customize_type: javascript 65 | comments: "" 66 | project_pattern: "" 67 | view_customize_007: 68 | id: 7 69 | path_pattern: /issues/new 70 | code: code_007 71 | is_enabled: true 72 | is_private: false 73 | author_id: 1 74 | insertion_position: issue_form 75 | customize_type: html 76 | comments: "" 77 | project_pattern: ecookbook|onlinestore 78 | view_customize_008: 79 | id: 8 80 | path_pattern: /issues/[0-9]+$ 81 | code: code_008 82 | is_enabled: true 83 | is_private: false 84 | author_id: 1 85 | insertion_position: issue_show 86 | customize_type: css 87 | comments: "" 88 | project_pattern: onlinestore 89 | view_customize_009: 90 | id: 9 91 | path_pattern: /issues$ 92 | code: code_009 93 | is_enabled: true 94 | is_private: false 95 | author_id: 1 96 | insertion_position: html_bottom 97 | customize_type: javascript 98 | comments: comment_009 99 | project_pattern: "" 100 | view_customize_010: 101 | id: 10 102 | path_pattern: "" 103 | code: code_010 104 | is_enabled: true 105 | is_private: false 106 | author_id: 1 107 | insertion_position: issues_context_menu 108 | customize_type: javascript 109 | comments: comment_010 110 | project_pattern: "" 111 | -------------------------------------------------------------------------------- /test/functional/view_customizes_controller_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../test_helper', __FILE__) 2 | 3 | class ViewCustomizesControllerTest < ActionController::TestCase 4 | # Replace this with your real tests. 5 | def test_truth 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # Load the Redmine helper 2 | require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') 3 | ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', 'view_customizes') 4 | -------------------------------------------------------------------------------- /test/unit/view_customize_view_hook_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../test_helper', __FILE__) 2 | require File.expand_path('../../../lib/redmine_view_customize/view_hook', __FILE__) 3 | 4 | class ViewCustomizeViewHookTest < ActiveSupport::TestCase 5 | fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles, 6 | :issues, :journals, :custom_fields, :custom_fields_projects, :custom_values, :time_entries, 7 | :view_customizes 8 | 9 | class Request 10 | def initialize(path) 11 | @path = path 12 | end 13 | 14 | def path_info 15 | @path 16 | end 17 | end 18 | 19 | def setup 20 | @project_ecookbook = Project.find(1) 21 | @project_onlinestore = Project.find(2) 22 | @hook = RedmineViewCustomize::ViewHook.instance 23 | end 24 | 25 | def test_match_customize 26 | 27 | User.current = User.find(1) 28 | 29 | matches = @hook.send(:match_customize, {:request => Request.new("/")}, ViewCustomize::INSERTION_POSITION_HTML_HEAD) 30 | assert_equal [2], matches.map {|x| x.id } 31 | 32 | # path pattern 33 | matches = @hook.send(:match_customize, {:request => Request.new("/issues")}, ViewCustomize::INSERTION_POSITION_HTML_HEAD) 34 | assert_equal [1, 2], matches.map {|x| x.id } 35 | 36 | matches = @hook.send(:match_customize, {:request => Request.new("/issues/1")}, ViewCustomize::INSERTION_POSITION_HTML_HEAD) 37 | assert_equal [2], matches.map {|x| x.id } 38 | 39 | # project pattern 40 | matches = @hook.send(:match_customize, {:request => Request.new("/issues"), :project => @project_ecookbook}, ViewCustomize::INSERTION_POSITION_HTML_HEAD) 41 | assert_equal [1, 2, 3], matches.map {|x| x.id } 42 | 43 | matches = @hook.send(:match_customize, {:request => Request.new("/issues"), :project => @project_onlinestore}, ViewCustomize::INSERTION_POSITION_HTML_HEAD) 44 | assert_equal [1, 2], matches.map {|x| x.id } 45 | 46 | # path and project pattern 47 | matches = @hook.send(:match_customize, {:request => Request.new("/issues/new"), :project => @project_ecookbook}, ViewCustomize::INSERTION_POSITION_HTML_HEAD) 48 | assert_equal [2, 3, 4], matches.map {|x| x.id } 49 | 50 | # private 51 | User.current = User.find(2) 52 | matches = @hook.send(:match_customize, {:request => Request.new("/")}, ViewCustomize::INSERTION_POSITION_HTML_HEAD) 53 | assert_equal [2, 6], matches.map {|x| x.id } 54 | 55 | # insertion position 56 | matches = @hook.send(:match_customize, {:request => Request.new("/issues")}, ViewCustomize::INSERTION_POSITION_ISSUE_FORM) 57 | assert_empty matches 58 | 59 | matches = @hook.send(:match_customize, {:request => Request.new("/issues/new"), :project => @project_ecookbook}, ViewCustomize::INSERTION_POSITION_ISSUE_FORM) 60 | assert_equal [7], matches.map {|x| x.id } 61 | matches = @hook.send(:match_customize, {:request => Request.new("/issues/new"), :project => @project_onlinestore}, ViewCustomize::INSERTION_POSITION_ISSUE_FORM) 62 | assert_equal [7], matches.map {|x| x.id } 63 | 64 | matches = @hook.send(:match_customize, {:request => Request.new("/issues/123"), :project => @project_onlinestore}, ViewCustomize::INSERTION_POSITION_ISSUE_SHOW) 65 | assert_equal [8], matches.map {|x| x.id } 66 | 67 | end 68 | 69 | def test_view_layouts_base_html_head 70 | 71 | User.current = User.find(1) 72 | 73 | expected = Regexp.escape("\n") 74 | expected << Regexp.escape("\n") 75 | expected << "(" 76 | expected << Regexp.escape("") 79 | expected << "|" 80 | expected << Regexp.escape("") 83 | expected << ")" 84 | expected << Regexp.escape("\n") 89 | expected << Regexp.escape("\n") 90 | expected << Regexp.escape("\n") 95 | expected << Regexp.escape("\n") 96 | expected << Regexp.escape("\n") 99 | expected << Regexp.escape("\n") 100 | expected << Regexp.escape("code_003\n") 101 | 102 | html = @hook.view_layouts_base_html_head({:request => Request.new("/issues"), :project => @project_ecookbook}) 103 | assert_match Regexp.new(expected), html 104 | 105 | end 106 | 107 | def test_project_custom_field_visible 108 | 109 | User.current = User.find(2) 110 | 111 | # Change project custom filed visible 112 | custom_field = CustomField.find(3) 113 | custom_field.visible = false 114 | custom_field.role_ids = [3] 115 | custom_field.save() 116 | 117 | expected = Regexp.escape("project\":{\"id\":1,\"identifier\":\"ecookbook\",\"name\":\"eCookbook\",\"roles\":[{\"id\":1,\"name\":\"Manager\"}],\"customFields\":[]}") 118 | 119 | html = @hook.view_layouts_base_html_head({:request => Request.new("/issues"), :project => @project_ecookbook}) 120 | assert_match Regexp.new(expected), html 121 | 122 | end 123 | 124 | def test_view_layouts_base_html_head_xss 125 | 126 | User.current = User.find(1) 127 | 128 | expected = Regexp.escape("\n") 129 | expected << Regexp.escape("\n") 130 | expected << ".+" 131 | 132 | html = @hook.view_layouts_base_html_head({:request => Request.new("/projects/-->

xss 144 | 149 | HTML 150 | 151 | html = @hook.view_layouts_base_body_bottom({:request => Request.new("/issues"), :project => @project_ecookbook}) 152 | assert_equal expected, html 153 | end 154 | 155 | def test_view_issues_context_menu_end 156 | 157 | User.current = User.find(1) 158 | 159 | expected = < 162 | 167 | HTML 168 | 169 | html = @hook.view_issues_context_menu_end({:request => Request.new("/issues")}) 170 | assert_equal expected, html 171 | end 172 | 173 | def test_view_issues_form_details_bottom 174 | 175 | User.current = User.find(1) 176 | 177 | expected = < 180 | code_007 181 | HTML 182 | 183 | html = @hook.view_issues_form_details_bottom({:request => Request.new("/issues/new"), :project => @project_ecookbook}) 184 | assert_equal expected, html 185 | 186 | end 187 | 188 | def test_view_issues_show_details_bottom 189 | 190 | User.current = User.find(1) 191 | issue = Issue.find(4) 192 | 193 | expected = < 196 | // 199 | 200 | 201 | 204 | HTML 205 | 206 | html = @hook.view_issues_show_details_bottom({:request => Request.new("/issues/4"), :issue => issue, :project => @project_onlinestore}) 207 | assert_equal expected, html 208 | 209 | end 210 | 211 | def test_view_issues_show_details_bottom_with_journals 212 | 213 | User.current = User.find(1) 214 | issue = Issue.find(6) 215 | 216 | expected = < 219 | // 222 | 223 | 224 | 227 | HTML 228 | 229 | html = @hook.view_issues_show_details_bottom({:request => Request.new("/issues/6"), :issue => issue, :project => @project_onlinestore}) 230 | assert_equal expected, html 231 | 232 | end 233 | 234 | def test_view_issues_show_details_bottom_with_time_entries 235 | 236 | User.current = User.find(1) 237 | issue = Issue.find(1) 238 | 239 | expected = < 242 | // 245 | 246 | 247 | 250 | HTML 251 | 252 | html = @hook.view_issues_show_details_bottom({:request => Request.new("/issues/1"), :issue => issue, :project => @project_onlinestore}) 253 | assert_equal expected, html 254 | 255 | end 256 | 257 | end 258 | --------------------------------------------------------------------------------