mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-12 06:54:19 +01:00
Merge branch 'steps' into dev
Conflicts: app/assets/javascripts/controllers/projects.coffee.erb db/schema.rb
This commit is contained in:
commit
68f9324725
@ -125,6 +125,20 @@ config(['$httpProvider', 'AuthProvider', "growlProvider", "unsavedWarningsConfig
|
|||||||
// see https://github.com/revolunet/angular-google-analytics#automatic-page-view-tracking
|
// see https://github.com/revolunet/angular-google-analytics#automatic-page-view-tracking
|
||||||
Analytics.pageView();
|
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', {
|
}]).constant('angularMomentConfig', {
|
||||||
timezone: Fablab.timezone
|
timezone: Fablab.timezone
|
||||||
});
|
});
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
# in the various projects' admin controllers.
|
# in the various projects' admin controllers.
|
||||||
#
|
#
|
||||||
# Provides :
|
# Provides :
|
||||||
|
# - $scope.totalSteps
|
||||||
# - $scope.machines = [{Machine}]
|
# - $scope.machines = [{Machine}]
|
||||||
# - $scope.components = [{Component}]
|
# - $scope.components = [{Component}]
|
||||||
# - $scope.themes = [{Theme}]
|
# - $scope.themes = [{Theme}]
|
||||||
@ -17,6 +18,7 @@
|
|||||||
# - $scope.deleteFile(file)
|
# - $scope.deleteFile(file)
|
||||||
# - $scope.addStep()
|
# - $scope.addStep()
|
||||||
# - $scope.deleteStep(step)
|
# - $scope.deleteStep(step)
|
||||||
|
# - $scope.changeStepIndex(step, newIdx)
|
||||||
#
|
#
|
||||||
# Requires :
|
# Requires :
|
||||||
# - $scope.project.project_caos_attributes = []
|
# - $scope.project.project_caos_attributes = []
|
||||||
@ -24,7 +26,7 @@
|
|||||||
# - $state (Ui-Router) [ 'app.public.projects_show', 'app.public.projects_list' ]
|
# - $state (Ui-Router) [ 'app.public.projects_show', 'app.public.projects_list' ]
|
||||||
##
|
##
|
||||||
class ProjectsController
|
class ProjectsController
|
||||||
constructor: ($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, Diacritics)->
|
constructor: ($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, Diacritics, dialogs, _t)->
|
||||||
|
|
||||||
## Retrieve the list of machines from the server
|
## Retrieve the list of machines from the server
|
||||||
Machine.query().$promise.then (data)->
|
Machine.query().$promise.then (data)->
|
||||||
@ -50,6 +52,8 @@ class ProjectsController
|
|||||||
id: d.id
|
id: d.id
|
||||||
name: d.name
|
name: d.name
|
||||||
|
|
||||||
|
$scope.totalSteps = $scope.project.project_steps_attributes.length
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -114,22 +118,52 @@ class ProjectsController
|
|||||||
# This will create a single new empty entry into the project's steps list.
|
# This will create a single new empty entry into the project's steps list.
|
||||||
##
|
##
|
||||||
$scope.addStep = ->
|
$scope.addStep = ->
|
||||||
$scope.project.project_steps_attributes.push {}
|
$scope.totalSteps += 1
|
||||||
|
$scope.project.project_steps_attributes.push { step_nb: $scope.totalSteps }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# This will remove the given stip from the project's steps list. If the step was previously saved
|
# This will remove the given step from the project's steps list. If the step was previously saved
|
||||||
# on the server, it will be marked for deletion for the next saving. Otherwise, it will be simply truncated from
|
# on the server, it will be marked for deletion for the next saving. Otherwise, it will be simply truncated from
|
||||||
# the steps array.
|
# the steps array.
|
||||||
# @param file {Object} the file to delete
|
# @param file {Object} the file to delete
|
||||||
##
|
##
|
||||||
$scope.deleteStep = (step) ->
|
$scope.deleteStep = (step) ->
|
||||||
index = $scope.project.project_steps_attributes.indexOf(step)
|
dialogs.confirm
|
||||||
if step.id?
|
resolve:
|
||||||
step._destroy = true
|
object: ->
|
||||||
else
|
title: _t('confirmation_required')
|
||||||
$scope.project.project_steps_attributes.splice(index, 1)
|
msg: _t('do_you_really_want_to_delete_this_step')
|
||||||
|
, -> # deletion confirmed
|
||||||
|
index = $scope.project.project_steps_attributes.indexOf(step)
|
||||||
|
if step.id?
|
||||||
|
step._destroy = true
|
||||||
|
else
|
||||||
|
$scope.project.project_steps_attributes.splice(index, 1)
|
||||||
|
|
||||||
|
# update the new total number of steps
|
||||||
|
$scope.totalSteps -= 1
|
||||||
|
# reindex the remaning steps
|
||||||
|
for s in $scope.project.project_steps_attributes
|
||||||
|
if s.step_nb > step.step_nb
|
||||||
|
s.step_nb -= 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Change the step_nb property of the given step to the new value provided. The step that was previously at this
|
||||||
|
# index will be assigned to the old position of the provided step.
|
||||||
|
# @param step {Object} the project's step to reindex
|
||||||
|
# @param newIdx {number} the new index to assign to the step
|
||||||
|
##
|
||||||
|
$scope.changeStepIndex = (step, newIdx) ->
|
||||||
|
for s in $scope.project.project_steps_attributes
|
||||||
|
if s.step_nb == newIdx
|
||||||
|
s.step_nb = step.step_nb
|
||||||
|
step.step_nb = newIdx
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
$scope.autoCompleteName = (nameLookup) ->
|
$scope.autoCompleteName = (nameLookup) ->
|
||||||
@ -278,8 +312,8 @@ Application.Controllers.controller "ProjectsController", ["$scope", "$state", 'P
|
|||||||
##
|
##
|
||||||
# Controller used in the project creation page
|
# Controller used in the project creation page
|
||||||
##
|
##
|
||||||
Application.Controllers.controller "NewProjectController", ["$scope", "$state", 'Project', 'Machine', 'Member', 'Component', 'Theme', 'Licence', '$document', 'CSRF', 'Diacritics'
|
Application.Controllers.controller "NewProjectController", ["$scope", "$state", 'Project', 'Machine', 'Member', 'Component', 'Theme', 'Licence', '$document', 'CSRF', 'Diacritics', 'dialogs', '_t'
|
||||||
, ($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, CSRF, Diacritics) ->
|
, ($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, CSRF, Diacritics, dialogs, _t) ->
|
||||||
CSRF.setMetaTags()
|
CSRF.setMetaTags()
|
||||||
|
|
||||||
## API URL where the form will be posted
|
## API URL where the form will be posted
|
||||||
@ -296,7 +330,7 @@ Application.Controllers.controller "NewProjectController", ["$scope", "$state",
|
|||||||
$scope.matchingMembers = []
|
$scope.matchingMembers = []
|
||||||
|
|
||||||
## Using the ProjectsController
|
## Using the ProjectsController
|
||||||
new ProjectsController($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, Diacritics)
|
new ProjectsController($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, Diacritics, dialogs, _t)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -304,8 +338,8 @@ Application.Controllers.controller "NewProjectController", ["$scope", "$state",
|
|||||||
##
|
##
|
||||||
# Controller used in the project edition page
|
# Controller used in the project edition page
|
||||||
##
|
##
|
||||||
Application.Controllers.controller "EditProjectController", ["$scope", "$state", '$stateParams', 'Project', 'Machine', 'Member', 'Component', 'Theme', 'Licence', '$document', 'CSRF', 'projectPromise', 'Diacritics'
|
Application.Controllers.controller "EditProjectController", ["$scope", "$state", '$stateParams', 'Project', 'Machine', 'Member', 'Component', 'Theme', 'Licence', '$document', 'CSRF', 'projectPromise', 'Diacritics', 'dialogs', '_t'
|
||||||
, ($scope, $state, $stateParams, Project, Machine, Member, Component, Theme, Licence, $document, CSRF, projectPromise, Diacritics) ->
|
, ($scope, $state, $stateParams, Project, Machine, Member, Component, Theme, Licence, $document, CSRF, projectPromise, Diacritics, dialogs, _t) ->
|
||||||
CSRF.setMetaTags()
|
CSRF.setMetaTags()
|
||||||
|
|
||||||
## API URL where the form will be posted
|
## API URL where the form will be posted
|
||||||
@ -322,7 +356,7 @@ Application.Controllers.controller "EditProjectController", ["$scope", "$state",
|
|||||||
name: u.full_name
|
name: u.full_name
|
||||||
|
|
||||||
## Using the ProjectsController
|
## Using the ProjectsController
|
||||||
new ProjectsController($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, Diacritics)
|
new ProjectsController($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, Diacritics, dialogs, _t)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,11 +72,20 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-2 control-label" translate>{{ 'steps' }}</label>
|
<label class="col-sm-2 control-label" translate>{{ 'steps' }}</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<div ng-repeat="step in project.project_steps_attributes" ng-show="!step._destroy">
|
<div ng-repeat="step in project.project_steps_attributes | orderBy:'step_nb'" ng-hide="step._destroy">
|
||||||
<div class="m-t-xs m-b-lg">
|
<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 } }}/{{totalSteps}} <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, totalSteps +1)"><a href="#" ng-click="changeStepIndex(step, 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][][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][][_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"
|
<input ng-model="step.title"
|
||||||
type="text"
|
type="text"
|
||||||
name="project[project_steps_attributes][][title]"
|
name="project[project_steps_attributes][][title]"
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<div class="article-steps">
|
<div class="article-steps">
|
||||||
<div class="row article-step m-b-lg" ng-repeat="step in project.project_steps_attributes">
|
<div class="row article-step m-b-lg" ng-repeat="step in project.project_steps_attributes">
|
||||||
<div class="col-md-12 m-b-xs">
|
<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>
|
||||||
<div class="col-md-4" ng-if="step.project_step_image">
|
<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>
|
<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>
|
||||||
|
@ -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,
|
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],
|
user_ids: [], machine_ids: [], component_ids: [], theme_ids: [], project_image_attributes: [:attachment],
|
||||||
project_caos_attributes: [:id, :attachment, :_destroy],
|
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])
|
:project_step_image_attributes => :attachment])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -46,12 +46,13 @@ json.project_users @project.project_users do |pu|
|
|||||||
json.slug pu.user.slug
|
json.slug pu.user.slug
|
||||||
json.is_valid pu.is_valid
|
json.is_valid pu.is_valid
|
||||||
end
|
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.id s.id
|
||||||
json.description s.description
|
json.description s.description
|
||||||
json.title s.title
|
json.title s.title
|
||||||
json.project_step_image s.project_step_image.attachment_identifier if s.project_step_image
|
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.project_step_image_url s.project_step_image.attachment.medium.url if s.project_step_image
|
||||||
|
json.step_nb s.step_nb
|
||||||
end
|
end
|
||||||
json.state @project.state
|
json.state @project.state
|
||||||
json.licence do
|
json.licence do
|
||||||
|
@ -121,6 +121,7 @@ en:
|
|||||||
add_a_picture: "Add a picture"
|
add_a_picture: "Add a picture"
|
||||||
change_the_picture: "Change the picture"
|
change_the_picture: "Change the picture"
|
||||||
delete_the_step: "Delete the step"
|
delete_the_step: "Delete the step"
|
||||||
|
do_you_really_want_to_delete_this_step: "Do you really want to delete this step?"
|
||||||
add_a_new_step: "Add a new step"
|
add_a_new_step: "Add a new step"
|
||||||
publish_your_project: "Publish your project"
|
publish_your_project: "Publish your project"
|
||||||
employed_materials: "Employed materials"
|
employed_materials: "Employed materials"
|
||||||
|
@ -121,6 +121,7 @@ fr:
|
|||||||
add_a_picture: "Ajouter une image"
|
add_a_picture: "Ajouter une image"
|
||||||
change_the_picture: "Modifier l'image"
|
change_the_picture: "Modifier l'image"
|
||||||
delete_the_step: "Supprimer l'étape"
|
delete_the_step: "Supprimer l'étape"
|
||||||
|
do_you_really_want_to_delete_this_step: "Êtes-vous sur de vouloir supprimer cette étape ?"
|
||||||
add_a_new_step: "Ajouter une nouvelle étape"
|
add_a_new_step: "Ajouter une nouvelle étape"
|
||||||
publish_your_project: "Publier votre projet"
|
publish_your_project: "Publier votre projet"
|
||||||
employed_materials: "Matériaux utilisés"
|
employed_materials: "Matériaux utilisés"
|
||||||
|
19
db/migrate/20160602075531_add_step_nb_to_project_step.rb
Normal file
19
db/migrate/20160602075531_add_step_nb_to_project_step.rb
Normal 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
|
@ -357,6 +357,7 @@ ActiveRecord::Schema.define(version: 20160613093842) do
|
|||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "title", limit: 255
|
t.string "title", limit: 255
|
||||||
|
t.integer "step_nb"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "project_steps", ["project_id"], name: "index_project_steps_on_project_id", using: :btree
|
add_index "project_steps", ["project_id"], name: "index_project_steps_on_project_id", using: :btree
|
||||||
|
Loading…
x
Reference in New Issue
Block a user