1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-03-21 12:29:03 +01:00

[bug] unable to search for projects on OpenLab

This commit is contained in:
Sylvain 2020-08-24 16:19:03 +02:00
parent 8278fd19df
commit d708f0a3e7
4 changed files with 32 additions and 10 deletions

View File

@ -1,5 +1,7 @@
# Changelog Fab-manager
- Fix a bug: unable to search for projects on OpenLab
## v4.5.4 2020 July 29
- Display an asterisk on the phone input field, in the admin creation form, if the phone is configured as required

View File

@ -73,7 +73,7 @@ If you want to try it, you can visit [this Fab-manager](https://fablab.lacasemat
To start using this awesome feature, there are a few steps:
- send a mail to **contact@fab-manager.com** asking for your Open Projects client's credentials and giving them the name and the URL of your Fab-manager, they will give you an `App ID` and a `secret`
- fill in the value of the keys in Admin > Projects > Settings > Projects sharing
- export your projects to open-projects (if you already have projects created on your Fab-manager, unless you can skip that part) executing this command: `bundle exec rake fablab:openlab:bulk_export`
- export your projects to open-projects (if you already have projects created on your Fab-manager, unless you can skip that part) executing this command: `bundle exec rails fablab:openlab:bulk_export`
**IMPORTANT: please run your server in production mode.**

View File

@ -306,13 +306,16 @@ Application.Controllers.controller('ProjectsController', ['$scope', '$state', 'P
// list of components / used for filtering
$scope.components = componentsPromise;
/**
* Callback triggered when the button "search from the whole network" is toggled
*/
$scope.searchOverWholeNetworkChanged = function () {
setTimeout(
function () { $scope.resetFiltersAndTriggerSearch(); },
150
);
$scope.resetFiltersAndTriggerSearch();
};
/**
* Callback to load the next projects of the result set, for the current search
*/
$scope.loadMore = function () {
if ($scope.openlab.searchOverWholeNetwork === true) {
return $scope.projectsPagination.loadMore({ q: $scope.search.q });
@ -321,6 +324,9 @@ Application.Controllers.controller('ProjectsController', ['$scope', '$state', 'P
}
};
/**
* Reinitialize the search filters (used by the projects from the instance DB) and trigger a new search query
*/
$scope.resetFiltersAndTriggerSearch = function () {
$scope.search.q = '';
$scope.search.from = undefined;
@ -331,13 +337,17 @@ Application.Controllers.controller('ProjectsController', ['$scope', '$state', 'P
return $scope.triggerSearch();
};
/**
* Query the list of projects. Depending on $scope.openlab.searchOverWholeNetwork, the resulting list
* will be fetched from OpenLab or from the instance DB
*/
$scope.triggerSearch = function () {
const currentPage = parseInt($location.$$search.page) || 1;
if ($scope.openlab.searchOverWholeNetwork === true) {
updateUrlParam('whole_network', 't');
$scope.projectsPagination = new paginationService.Instance(OpenlabProject, currentPage, PROJECTS_PER_PAGE, null, { }, loadMoreOpenlabCallback);
return OpenlabProject.query({ q: $scope.search.q, page: currentPage, per_page: PROJECTS_PER_PAGE }, function (projectsPromise) {
if (projectsPromise.errors != null) {
if (projectsPromise.errors) {
growl.error(_t('app.public.projects_list.openlab_search_not_available_at_the_moment'));
$scope.openlab.searchOverWholeNetwork = false;
return $scope.triggerSearch();
@ -357,7 +367,7 @@ Application.Controllers.controller('ProjectsController', ['$scope', '$state', 'P
};
/**
* Callback to switch the user's view to the detailled project page
* Callback to switch the user's view to the detailed project page
* @param project {{slug:string}} The project to display
*/
$scope.showProject = function (project) {
@ -402,17 +412,25 @@ Application.Controllers.controller('ProjectsController', ['$scope', '$state', 'P
const updateUrlParam = function (name, value) {
$state.current.reloadOnSearch = false;
$location.search(name, value);
return $timeout(function () { $state.current.reloadOnSearch = undefined; });
$timeout(function () { $state.current.reloadOnSearch = undefined; });
};
/**
* Callback triggered when the next projects were loaded from the result set (from the instance DB)
* @param projectsPromise {{projects: []}}
*/
const loadMoreCallback = function (projectsPromise) {
$scope.projects = $scope.projects.concat(projectsPromise.projects);
return updateUrlParam('page', $scope.projectsPagination.currentPage);
updateUrlParam('page', $scope.projectsPagination.currentPage);
};
/**
* Callback triggered when the next projects were loaded from the result set (from OpenLab)
* @param projectsPromise {{projects: []}}
*/
const loadMoreOpenlabCallback = function (projectsPromise) {
$scope.projects = $scope.projects.concat(normalizeProjectsAttrs(projectsPromise.projects));
return updateUrlParam('page', $scope.projectsPagination.currentPage);
updateUrlParam('page', $scope.projectsPagination.currentPage);
};
const normalizeProjectsAttrs = function (projects) {

View File

@ -861,6 +861,8 @@ Setting.set('email_from', 'noreply@fab-manager.com') unless Setting.find_by(name
Setting.set('online_payment_module', false) unless Setting.find_by(name: 'online_payment_module').try(:value)
Setting.set('openlab_default', true) unless Setting.find_by(name: 'openlab_default').try(:value)
unless Setting.find_by(name: 'allowed_cad_extensions').try(:value)
Setting.set(
'allowed_cad_extensions',