Skip to content
This repository was archived by the owner on Nov 17, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion app/scripts/controllers/venues.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
'use strict';

angular.module('barteguidenMarkedsWebApp')
.controller('VenuesCtrl', function ($scope, Venue, $modal, $window, $location) {
.controller('VenuesCtrl', function ($scope, Venue, notify, $modal, $window, $location) {

$scope.orderProperty = 'name';
$scope.reverse = false;

$scope.numberToMerge = 0;

$scope.order = function(orderProperty){
$scope.reverse = ($scope.orderProperty === orderProperty) ? !$scope.reverse : false;
$scope.orderProperty = orderProperty;
Expand All @@ -38,6 +40,14 @@ angular.module('barteguidenMarkedsWebApp')
$location.path('/venue/' + id);
};

$scope.toggleToMerge = function(venue) {
if(venue.selectedForMerge) {
$scope.numberToMerge += 1;
}else{
$scope.numberToMerge -= 1;
}
}

$scope.open = function (id) {
var scope = $scope.$new(true);
scope.params = {elementType: 'Stedet'};
Expand All @@ -64,4 +74,53 @@ angular.module('barteguidenMarkedsWebApp')
$scope.$dismiss('cancel');
};

$scope.okMergeVenues = function () {
$scope.$close($scope.representativeVenue);
}

$scope.openModalMergeVenues = function () {
var scope = $scope.$new(true);
var selectedVenues = $scope.venues.filter(function(venue) {return venue.selectedForMerge});
scope.selectedVenues = selectedVenues;
var modalInstance = $modal.open({
scope: scope,
templateUrl: 'views/venuemergemodal.html',
controller: 'VenuesCtrl',
size: 'lg'
});
modalInstance.result.then(function (representativeVenue) {
selectedVenues.splice(selectedVenues.indexOf(representativeVenue), 1);
selectedVenues.forEach((venue) => {
if(representativeVenue.aliases.indexOf(venue.name) == -1){
representativeVenue.aliases.push(venue.name);
}
venue.aliases.forEach((otherAlias) => {
if(representativeVenue.aliases.indexOf(otherAlias) == -1){
representativeVenue.aliases.push(otherAlias);
}
});
Venue.delete({id: venue._id});
var index;
if((index = $scope.venues.indexOf(venue)) >=0){
$scope.venues.splice($scope.venues.indexOf(venue), 1);
}
});

representativeVenue.selectedForMerge = false;
$scope.numberToMerge = 0;

var venueObject = new Venue(representativeVenue);

venueObject.$update({id: representativeVenue._id}, function() {
notify({message: 'Stedene er slått sammen!', classes: 'alert-success'});
}, function () {
notify({message: 'Noe gikk galt!', classes: 'alert-danger'});
});
});
}

$scope.setRepresentative = function (venue) {
$scope.representativeVenue = venue;
}

});
54 changes: 54 additions & 0 deletions app/views/venuemergemodal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!--
~ Copyright 2016 Studentmediene i Trondheim AS
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<div class="modal-header">
<h3 class="modal-title">Velg representant for stedene</h3>
</div>
<div class="modal-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>
<span>Navn</span>
</th>
<th>
<span>Adresse</span>
</th>
<th>
<span>Representant</span>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="venue in selectedVenues | orderBy : 'name'">
<td>
{{venue.name}}
</td>
<td>
{{venue.address}}
</td>
<td>
<input type="radio" name="representative" value="{{venue.name}}" ng-click="setRepresentative(venue)">
</td>
</tr>
</tbody>
</table>
</div>
<div class=modal-footer>
<button class="btn-warning btn" ng-click="okMergeVenues()" ng-if="representativeVenue!=undefined">Ok</button>
<button class="btn btn-info" ng-click="cancel()">Avbryt</button>
</div>
18 changes: 15 additions & 3 deletions app/views/venues.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ <h3>Steder</h3>
<div class="input-group row">
<div class="col-md-4">
<button class="btn btn-md btn-info" ng-click="addVenue()">
<span class="glyphicon glyphicon-plus"></span> Legg til sted
Legg til sted
</button>
</div>
<div class="col-md-6">
<div class="col-md-4">
<div class="input-group">
<input ng-model="search.name" type="text" class="form-control" aria-label="..." placeholder="Søk på sted">
</div>
</div>
<div class="col-md-4">
<button class="btn btn-md btn-warning" ng-click="openModalMergeVenues()"
ng-if="numberToMerge > 1"
>
Slå sammen steder
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-striped">
Expand All @@ -36,7 +43,7 @@ <h3>Steder</h3>
<th>
<a href="" ng-click="order('address')">Adresse</a>
</th>
<th>Endre</th><th>Slett</th>
<th>Slå sammen</th><th>Endre</th><th>Slett</th>
</tr>
</thead>
<tbody>
Expand All @@ -47,6 +54,11 @@ <h3>Steder</h3>
<td>
{{venue.address}}
</td>
<td>
<input type="checkbox" name="tomerge" value="{{value}}"
ng-click="toggleToMerge(venue)"
ng-checked="false" ng-model="venue.selectedForMerge">
</td>
<td>
<button ng-click="editVenue(venue._id)" class="btn btn-xs btn-info">Endre</button>
</td>
Expand Down
54 changes: 45 additions & 9 deletions server/import/server_sync.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
var Event = require('../models/Event.js');
var Venue = require('../models/Venue.js');

function escapeString(string){ //Makes string possible to match with regex
return string.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&");
}

exports.sync = function(events) {
events.map(function(evt) {

Expand Down Expand Up @@ -52,10 +56,40 @@ exports.sync = function(events) {
);
}

if(evt.venue.name == null)
return;

//Match venues with same name or whose aliases-list contains name,
//or venues with same, non-null address
var venuequery = {
'name': evt.venue.name
$or: [
{'name':
{ $regex: new RegExp('^' +
escapeString(evt.venue.name) +
'$', "i")}
},
{'aliases':
{ $regex: new RegExp('^' +
escapeString(evt.venue.name) +
'$', "i")}
},
{ $and: [
{
'address':
evt.venue.address == null ? null :
{ $regex: new RegExp('^' +
escapeString(evt.venue.address) +
'$', "i")}
},
{
'address':
{$ne: null}
}
]
}
]
};

var venue = {
'name': evt.venue.name,
'address': evt.venue.address,
Expand All @@ -64,14 +98,16 @@ exports.sync = function(events) {
};

Venue.findOneAndUpdate(
venuequery,
venue,
{'upsert': true},
function(err, doc) {
if (err) {
console.error("Venue error: ", err);
}
venuequery,
{$setOnInsert: venue},
{'upsert': true, 'new': true},
function(err, doc){
if (err) {
console.error("Venue error: ", err);
}else if (doc.name) {
evt.venue.name = doc.name;
}
);
}
)
});
};
1 change: 1 addition & 0 deletions server/models/Venue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var mongoose = require('mongoose');

var VenueSchema = new mongoose.Schema({
name: {type: String, trim: true},
aliases: {type: [String], required: true, default: []},
address: {type: String, trim: true},
latitude: Number,
longitude: Number
Expand Down