diff --git a/.codeclimate.yml b/.codeclimate.yml index 8a39dff..17c7963 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -3,4 +3,10 @@ exclude_patterns: - "public/js/PLYLoader.js" - "public/js/STLLoader.js" - "public/js/three.min.js" +- "public/js/OBJLoader.js" +- "public/js/OBJLoader2.js" +- "public/js/LoaderSupport.js" +- "public/js/OutlinePass.js" +- "public/js/MTLLoader.js" +- "public/js/EffectComposer.js" - "db" diff --git a/.travis.yml b/.travis.yml index 3da92c0..51f08eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ +addons: + postgresql: 9.6 + language: ruby os: linux @@ -11,9 +14,9 @@ before_install: env: - DB=postgresql -before_script: - - rails db:create - - rails db:migrate +script: + - rails db:drop db:create db:migrate RAILS_ENV=test + - rails test rvm: - - 2.3.3 + - 2.5.0 diff --git a/Gemfile.lock b/Gemfile.lock index 07cf239..892029a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/codahale/bcrypt-ruby.git - revision: 011b67ba550457dab5d6084128888f08476f278a + revision: 2875dbf4359ef9ce88775f4aae67aaa011f930fa specs: bcrypt (3.1.13) @@ -98,16 +98,16 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.1.5) - crass (1.0.4) - devise (4.6.2) + crass (1.0.5) + devise (4.7.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 6.0) + railties (>= 4.1.0) responders warden (~> 1.2.3) - devise-i18n (1.8.0) - devise (>= 4.6) - erubi (1.8.0) + devise-i18n (1.9.0) + devise (>= 4.7.1) + erubi (1.9.0) execjs (2.7.0) ffi (1.11.1) ffi (1.11.1-x86-mingw32) @@ -119,7 +119,7 @@ GEM multi_json request_store (>= 1.0) high_voltage (3.1.2) - i18n (1.6.0) + i18n (1.7.0) concurrent-ruby (~> 1.0) jbuilder (2.9.1) activesupport (>= 4.2.0) @@ -140,7 +140,7 @@ GEM activerecord kaminari-core (= 1.1.1) kaminari-core (1.1.1) - loofah (2.2.3) + loofah (2.4.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -151,12 +151,12 @@ GEM mimemagic (0.3.3) mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.11.3) + minitest (5.13.0) multi_json (1.13.1) nio4r (2.4.0) - nokogiri (1.10.3) + nokogiri (1.10.7) mini_portile2 (~> 2.4.0) - nokogiri (1.10.3-x86-mingw32) + nokogiri (1.10.7-x86-mingw32) mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) pg (1.1.4) @@ -187,8 +187,8 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) railties (5.2.3) actionpack (= 5.2.3) activesupport (= 5.2.3) diff --git a/README.md b/README.md index 3bbd8d5..10ce53c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,150 @@ # FragmentX + ## 3D Visualization of restored objects [![Build Status](https://travis-ci.org/FragmentX/FRAGMENTX.svg?branch=master)](https://travis-ci.org/FragmentX/FRAGMENTX) [![Maintainability](https://api.codeclimate.com/v1/badges/900fd8a114c8d71e0142/maintainability)](https://codeclimate.com/github/FragmentX/FRAGMENTX/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/900fd8a114c8d71e0142/test_coverage)](https://codeclimate.com/github/FragmentX/FRAGMENTX/test_coverage) [![security](https://hakiri.io/github/FragmentX/FRAGMENTX/master.svg)](https://hakiri.io/github/FragmentX/FRAGMENTX/master) -http://scanviewer.herokuapp.com/ \ No newline at end of file + + +[//]: # (badges) +[![security](https://img.shields.io/badge/contributors-4-blue)](https://img.shields.io/badge/contributors-4-blue) + +[//]: # (badges) + +> [FragmentX web](http://scanviewer.herokuapp.com/) +> +> [http://scanviewer.herokuapp.com/](http://scanviewer.herokuapp.com/) +> + +## Description + FragmentX is an open source 3D objects viewer build using Ruby on Rails and Three JS. Is part of an European project in the UPV and the final degree project of one of the creators. + +FragmentX tries to bring to museums in particular and people in general a tool to store and visualize masterpieces and any type of 3D objects. Often this kind of objects are fragmented or divided in several pieces. Our 3D viewer is able to show all the fragments of these objects. + +The platform created is on the web because we wanted to create a more accessible tool for everybody. It could be used in any device. + +## Version +The application is under development. This means that there is not a release or a beta version yet. The FragmentX team and its community is working on its first beta release. + +### 0.2 Alpha 20181127 +#### Features +* [X] OBJ file format loader +* [X] Orthographic and Perspective cameras switch +* [X] Added continuous Integration +* [X] Added code quality checker +* [X] Added vulnerability checker +* [X] Added dependaBot +#### Bugs +* [X] Orthographic fails when is switched a few times + + +#### Changes +* [X] Redesigned interface +* [X] Refactored Code + + +### 0.1 Alpha 20180713 + +#### Features +* [X] STL file format loader +* [X] ZIP automatic restored object loader +* [X] 3D Restored Object viewer +* [X] Clipping X, Y, Z planes +* [X] Canvas Screenshoot +* [X] Pieces measurement +* [X] Show nearby pieces +* [X] Basic design and lading page +* [X] Async pieces loader using ThreeJS web workers +* [X] Automatic deploy on Heroku +* [X] Translations (English and Spanish) + + +## Installation + +### Dependecies +* Ruby version: [2.6](https://www.ruby-lang.org/es/news/2019/03/13/ruby-2-6-2-released/) +* Rails version: [5.2.3](https://weblog.rubyonrails.org/2019/3/28/Rails-5-2-3-has-been-released/) +* PostgreSQL version: [9.5](https://www.postgresql.org/docs/9.5/index.html) +* NodeJS version: [10.16.3](https://nodejs.org/uk/blog/release/v0.10.16/) +* gcc and g++ version: [5.4](https://ftp.gnu.org/gnu/gcc/gcc-5.4.0/) + +### Recomended +* Ubuntu 16.04~18.04, Kubuntu, or Debian based OS +* Git +### Installation steps + +* Update the Ubuntu repositories +```shell +sudo apt-get update +``` +* Install basic dependencies for Ruby on Rails (Git is optional) +```shell +sudo apt-get install git +sudo apt install curl +sudo apt install -y nodejs +sudo apt install gcc g++ make +``` +* Clone the repo from our master branch +```shell +git clone https://github.com/FragmentX/FRAGMENTX.git +cd FRAGMENTX/ +``` +* Ruby installation and basic setup of the rvm +```shell +gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB +curl -sSL https://get.rvm.io | bash -s stable --ruby +source /home/duxy1996/.rvm/scripts/rvm +rvm install ruby-2.6.1 +rvm --default use ruby-2.6.1 +``` +* Rails 5.2.0 installation +```shell +gem update --system +gem install rails -v 5.2.0 +``` +* PostgreSQL database installation and postgresql gem installation +```shell +sudo apt install postgresql postgresql-contrib libpq-dev -y +systemctl start postgresql +systemctl enable postgresql +``` +* Ruby basic gem installation +```shell +sudo apt-get install ruby-railties +sudo apt install ruby-bundler +bundle install +``` +* Database creation and migration. Applies all the changes made in the migrations folder. It is empty, to feed the database should run ` rails db:seed`. With the `rails s` command the appplication is launched in localhost:3000 +```shell +rails db:create +rails db:migrate +rails s +``` +#### Optional +PostgreSQL sometimes is not well set up. You have to modify the file **pg_hba.conf** to allow to enter to the database and create the profile/user for manage the application databases. +```shell +sudo gedit /etc/postgresql/9.5/main/pg_hba.conf +``` + +## Contributors + + + [Álvaro Casado Coscollá.](https://github.com/alvarocasadoc) Architect and developer + + [ Carlos Durán Roca.](https://github.com/Duxy1996) Architect and developer + + [Dependa Baller bot.](https://github.com/marketplace/dependabot-preview) + +[//]: # (contributors) + + + + +## References + + +* [Ruby tests for models and controllers](https://guides.rubyonrails.org/testing.html) +* [PostgreSQL test database initialization error](https://stackoverflow.com/questions/19097558/pg-undefinedtable-error-relation-users-does-not-exist) +* [PostgreSQL test fixture error](https://stackoverflow.com/questions/58190137/database-error-on-executing-test-ruby-on-rails-with-postgres) +* [PostgreSQL Travis configuration](https://medium.com/hexient-labs/configuring-travis-ci-for-a-rails-project-d25bc2f2ba7e) + diff --git a/app/controllers/restored_objects_controller.rb b/app/controllers/restored_objects_controller.rb index 97842d4..f05790e 100644 --- a/app/controllers/restored_objects_controller.rb +++ b/app/controllers/restored_objects_controller.rb @@ -52,24 +52,13 @@ def create authorize @object if params[:zip_file] params[:pieces_attributes] = nil - puts "About to read the file" Zip::File.open(params[:zip_file].path) do |zipfile| - puts "Reading zip file" zipfile.glob('*{ply,stl,obj}') do |file| - puts "Reading #{file.name}" - # tempfile = Tempfile.new(File.basename(file.name)) - # tempfile.binmode - # tempfile.write file.get_input_stream.read - - puts "Reading matrix" matrix = zipfile.glob("#{file.name.split('.').first}.txt").first.get_input_stream.read - puts matrix - piece = @object.pieces.create(name: file.name, matrix: matrix) end end end - respond_to do |format| if @object.save format.html { redirect_to @object } diff --git a/app/models/object_format.rb b/app/models/object_format.rb deleted file mode 100644 index 33293ad..0000000 --- a/app/models/object_format.rb +++ /dev/null @@ -1,2 +0,0 @@ -class ObjectFormat < ApplicationRecord -end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 94c08b0..2ca5192 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -18,6 +18,7 @@ +<% if @featured_museum != nil %> <%= link_to @featured_museum, class: "no-decoration" do %> +<% end %>
@@ -132,4 +134,4 @@ function render() { document.addEventListener("turbolinks:load", function() { render(); }); - \ No newline at end of file + diff --git a/app/views/restored_objects/index.html.erb b/app/views/restored_objects/index.html.erb index d565077..bf6c7e5 100644 --- a/app/views/restored_objects/index.html.erb +++ b/app/views/restored_objects/index.html.erb @@ -52,7 +52,7 @@
- <% @objects.sort[3..-1].each_with_index do |obj, index| %> + <% @objects.each_with_index do |obj, index| %>
<%= link_to image_tag(obj.featured_image, class:'card-img-top'), obj %>
diff --git a/badges/badgesGen.rb b/badges/badgesGen.rb new file mode 100644 index 0000000..ef9fd81 --- /dev/null +++ b/badges/badgesGen.rb @@ -0,0 +1,138 @@ +require 'httparty' +require 'json' + +localhost_format = false +verbose_mode = false +write_post_stats = false + +ARGV.each do |command| + case command + when "-v" # Verbose mode + verbose_mode = true + when "-w" # Store POST request in localhost + write_post_stats = true + when "-l" # Localhost mode + localhost_format = true + end +end + +class BadgeGenerator + + @verbose_mode = false + @localhost_format = false + + def initialize verbose_mode_tmp, localhost_format_tmp + @verbose_mode = verbose_mode_tmp + @localhost_format = localhost_format_tmp + end + + def getGeneralInformation + return HTTParty.get('https://api.github.com/repos/FragmentX/FRAGMENTX').body + end + + def getStatsInformation + return HTTParty.get('https://api.github.com/repos/FragmentX/FRAGMENTX/stats/contributors').body + end + + def getGeneralInformationFromLocalhost(file_name = "test_G.json") + tmp_file_content = File.open(file_name, "r").read + return tmp_file_content + end + + def getStatsInformationFromLocalhost(file_name = "test_S.json") + tmp_file_content = File.open(file_name, "r").read + return tmp_file_content + end + + def saveGenInfoGetRequest(file_name = "test_G.json") + writeFile(file_name, getGeneralInformation) + end + + def saveStatInfoGetRequest(file_name = "test_S.json") + writeFile(file_name, getStatsInformation) + end + + def writeFile(file_name = "test.json", data) + file = File.open(file_name, "w") + file.puts data + file.close + end + + def readREADMEFile + tmp_file_content = File.open("../README.md", "r").read + return tmp_file_content + end + + def writeREADMEFile(data) + file = File.open("../README.md", "w") + file.puts data + file.close + end + + def getNumberofcontributors + if @localhost_format + return JSON.parse(getStatsInformationFromLocalhost)[0]['total'] + else + return JSON.parse(getStatsInformation)[0]['total'] + end + end + + def getContributorsBadge + number_of_contributors = getNumberofcontributors + return crateBadge "contributors", (number_of_contributors.to_s), "blue" + end + + def createContributorsSticker + contributors_badge_raw = getContributorsBadge + return crateReadmeSticker contributors_badge_raw + end + + def crateBadge label, message, color + return "https://img.shields.io/badge/" + label + "-" + message + "-" + color + end + + def crateReadmeSticker stickerURL, stickerLink = nil + if stickerLink.nil? + stickerLink = stickerURL + end + return "[![security](" + stickerURL + ")]("+ stickerLink +")" + end + + def createFixedStickerList + stickerList = createContributorsSticker + return stickerList + end + + def createFileStickerList + + end + + def createStickersList + return createFixedStickerList + end + + def createUpdateStickerText + sticker_list = createStickersList + return readREADMEFile.sub /\[\/\/\]: # \(badges\)(.|\n)*\[\/\/\]: # \(badges\)/, "[//]: # (badges)\n" + sticker_list + "\n\n[//]: # (badges)" + end + + def updateReadme + updated_readme_file = createUpdateStickerText + writeREADMEFile updated_readme_file + if @verbose_mode + puts updated_readme_file + end + end +end + +generator = BadgeGenerator. new false, localhost_format + +generator.updateReadme + +if write_post_stats + generator.getStatsInformationFromLocalhost + generator.saveGenInfoGetRequest +end + +#puts JSON.parse(getStatsInformationFromLocalhost)[1]['author'] + diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 0000000..8e8d6d7 --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class CategoriesControllerTest < ActionDispatch::IntegrationTest + test "show categories index" do + get '/categories' + assert_response :success + end +end \ No newline at end of file diff --git a/test/fixtures/categories.yml b/test/fixtures-back/categories.yml similarity index 100% rename from test/fixtures/categories.yml rename to test/fixtures-back/categories.yml diff --git a/test/fixtures/categories_restored_objects.yml b/test/fixtures-back/categories_restored_objects.yml similarity index 100% rename from test/fixtures/categories_restored_objects.yml rename to test/fixtures-back/categories_restored_objects.yml diff --git a/test/fixtures/collections.yml b/test/fixtures-back/collections.yml similarity index 100% rename from test/fixtures/collections.yml rename to test/fixtures-back/collections.yml diff --git a/test/fixtures/collections_restored_objects.yml b/test/fixtures-back/collections_restored_objects.yml similarity index 100% rename from test/fixtures/collections_restored_objects.yml rename to test/fixtures-back/collections_restored_objects.yml diff --git a/test/fixtures/compositions.yml b/test/fixtures-back/compositions.yml similarity index 100% rename from test/fixtures/compositions.yml rename to test/fixtures-back/compositions.yml diff --git a/test/fixtures/deteriorations.yml b/test/fixtures-back/deteriorations.yml similarity index 100% rename from test/fixtures/deteriorations.yml rename to test/fixtures-back/deteriorations.yml diff --git a/test/fixtures/deteriorations_restored_objects.yml b/test/fixtures-back/deteriorations_restored_objects.yml similarity index 100% rename from test/fixtures/deteriorations_restored_objects.yml rename to test/fixtures-back/deteriorations_restored_objects.yml diff --git a/test/fixtures/materials.yml b/test/fixtures-back/materials.yml similarity index 100% rename from test/fixtures/materials.yml rename to test/fixtures-back/materials.yml diff --git a/test/fixtures/pieces.yml b/test/fixtures-back/pieces.yml similarity index 100% rename from test/fixtures/pieces.yml rename to test/fixtures-back/pieces.yml diff --git a/test/fixtures/priorities.yml b/test/fixtures-back/priorities.yml similarity index 100% rename from test/fixtures/priorities.yml rename to test/fixtures-back/priorities.yml diff --git a/test/fixtures/protections.yml b/test/fixtures-back/protections.yml similarity index 100% rename from test/fixtures/protections.yml rename to test/fixtures-back/protections.yml diff --git a/test/fixtures/restored_objects.yml b/test/fixtures-back/restored_objects.yml similarity index 88% rename from test/fixtures/restored_objects.yml rename to test/fixtures-back/restored_objects.yml index ac01ab2..add51f2 100644 --- a/test/fixtures/restored_objects.yml +++ b/test/fixtures-back/restored_objects.yml @@ -3,11 +3,9 @@ one: title: MyString description: MyText - category: 1 user_id: 1 two: title: MyString description: MyText - category: 1 user_id: 1 diff --git a/test/fixtures/states.yml b/test/fixtures-back/states.yml similarity index 100% rename from test/fixtures/states.yml rename to test/fixtures-back/states.yml diff --git a/test/fixtures/units.yml b/test/fixtures-back/units.yml similarity index 100% rename from test/fixtures/units.yml rename to test/fixtures-back/units.yml diff --git a/test/fixtures/users.yml b/test/fixtures-back/users.yml similarity index 100% rename from test/fixtures/users.yml rename to test/fixtures-back/users.yml diff --git a/test/fixtures/object_formats.yml b/test/fixtures/object_formats.yml deleted file mode 100644 index 56066c6..0000000 --- a/test/fixtures/object_formats.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -one: - name: MyString - -two: - name: MyString diff --git a/test/models/material_test.rb b/test/models/material_test.rb new file mode 100644 index 0000000..62c3248 --- /dev/null +++ b/test/models/material_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class MaterialTest < ActiveSupport::TestCase + test "create material without arguments" do + material = Material.new + assert material.save + end +end \ No newline at end of file