1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

[feature] basic ability manage steps order

This commit is contained in:
Sylvain 2016-06-02 12:49:00 +02:00
parent 70ff027792
commit 2b1d1fc4dd
8 changed files with 50 additions and 6 deletions

View File

@ -125,6 +125,20 @@ config(['$httpProvider', 'AuthProvider', "growlProvider", "unsavedWarningsConfig
// see https://github.com/revolunet/angular-google-analytics#automatic-page-view-tracking
Analytics.pageView();
/**
* This helper method builds and return an array contaning every integers between
* the provided start and end.
* @param start {number}
* @param end {number}
* @return {Array} [start .. end]
*/
$rootScope.intArray = function(start, end) {
var arr = [];
for (var i = start; i < end; i++) { arr.push(i); }
return arr;
};
}]).constant('angularMomentConfig', {
timezone: Fablab.timezone
});

View File

@ -122,7 +122,7 @@ class ProjectsController
# This will create a single new empty entry into the project's steps list.
##
$scope.addStep = ->
$scope.project.project_steps_attributes.push {}
$scope.project.project_steps_attributes.push { step_nb: $scope.project.project_steps_attributes.length + 1 }

View File

@ -74,9 +74,18 @@
<div class="col-sm-10">
<div ng-repeat="step in project.project_steps_attributes" ng-show="!step._destroy">
<div class="m-t-xs m-b-lg">
<span class="label label-warning m-t m-b">{{ 'step_N' | translate:{ INDEX:$index+1 } }}/{{project.project_steps_attributes.length}}</span>
<div class="btn-group" uib-dropdown is-open="status.isopen">
<button id="single-button" type="button" class="btn btn-warning" uib-dropdown-toggle>
{{ 'step_N' | translate:{ INDEX:step.step_nb } }}/{{project.project_steps_attributes.length}} <i class="fa fa-caret-down" aria-hidden="true"></i>
</button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="single-button">
<li role="menuitem" ng-repeat="step_idx in intArray(1, project.project_steps_attributes.length +1)"><a href="#" ng-click="step.step_nb = step_idx">{{ 'step_N' | translate:{ INDEX:step_idx } }}</a></li>
</ul>
</div>
<span class="label label-warning m-t m-b"></span>
<input type="hidden" name="project[project_steps_attributes][][id]" ng-value="step.id" />
<input type="hidden" name="project[project_steps_attributes][][_destroy]" ng-value="step._destroy" />
<input type="hidden" name="project[project_steps_attributes][][step_nb]" ng-value="step.step_nb" />
<input ng-model="step.title"
type="text"
name="project[project_steps_attributes][][title]"

View File

@ -40,7 +40,7 @@
<div class="article-steps">
<div class="row article-step m-b-lg" ng-repeat="step in project.project_steps_attributes">
<div class="col-md-12 m-b-xs">
<h3 class="well well-simple step-title">{{ 'step_N' | translate:{INDEX:$index+1} }} : {{step.title}}</h3>
<h3 class="well well-simple step-title">{{ 'step_N' | translate:{INDEX:step.step_nb} }} : {{step.title}}</h3>
</div>
<div class="col-md-4" ng-if="step.project_step_image">
<a href="{{step.project_step_image_url}}" target="_blank"><img class="img-responsive m-b" ng-src="{{step.project_step_image_url}}" alt="{{step.title}}" ></a>

View File

@ -66,7 +66,7 @@ class API::ProjectsController < API::ApiController
params.require(:project).permit(:name, :description, :tags, :machine_ids, :component_ids, :theme_ids, :licence_id, :author_id, :licence_id, :state,
user_ids: [], machine_ids: [], component_ids: [], theme_ids: [], project_image_attributes: [:attachment],
project_caos_attributes: [:id, :attachment, :_destroy],
project_steps_attributes: [:id, :description, :title, :_destroy,
project_steps_attributes: [:id, :description, :title, :_destroy, :step_nb,
:project_step_image_attributes => :attachment])
end
end

View File

@ -46,12 +46,13 @@ json.project_users @project.project_users do |pu|
json.slug pu.user.slug
json.is_valid pu.is_valid
end
json.project_steps_attributes @project.project_steps.order('project_steps.created_at ASC') do |s|
json.project_steps_attributes @project.project_steps.order('project_steps.step_nb ASC') do |s|
json.id s.id
json.description s.description
json.title s.title
json.project_step_image s.project_step_image.attachment_identifier if s.project_step_image
json.project_step_image_url s.project_step_image.attachment.medium.url if s.project_step_image
json.step_nb s.step_nb
end
json.state @project.state
json.licence do

View File

@ -0,0 +1,19 @@
class AddStepNbToProjectStep < ActiveRecord::Migration
def up
add_column :project_steps, :step_nb, :integer
execute 'UPDATE project_steps
SET step_nb = subquery.index
FROM (
SELECT
id, project_id, created_at,
row_number() OVER (PARTITION BY project_id) AS index
FROM project_steps
ORDER BY created_at
) AS subquery
WHERE project_steps.id = subquery.id;'
end
def down
remove_column :project_steps, :step_nb
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160526102307) do
ActiveRecord::Schema.define(version: 20160602075531) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -337,6 +337,7 @@ ActiveRecord::Schema.define(version: 20160526102307) do
t.datetime "created_at"
t.datetime "updated_at"
t.string "title", limit: 255
t.integer "step_nb"
end
add_index "project_steps", ["project_id"], name: "index_project_steps_on_project_id", using: :btree