mirror of
https://github.com/nextcloud/maps.git
synced 2025-08-16 16:18:13 +00:00
Improved Contacts add to map
Signed-off-by: Arne Hamann <git@arne.email>
This commit is contained in:
@ -32,6 +32,7 @@ return [
|
||||
['name' => 'contacts#getContacts', 'url' => '/contacts', 'verb' => 'GET'],
|
||||
['name' => 'contacts#searchContacts', 'url' => '/contacts-search', 'verb' => 'GET'],
|
||||
['name' => 'contacts#placeContact', 'url' => '/contacts/{bookid}/{uri}', 'verb' => 'PUT'],
|
||||
['name' => 'contacts#addContactToMap', 'url' => '/contacts/{bookid}/{uri}/add-to-map/', 'verb' => 'PUT'],
|
||||
['name' => 'contacts#deleteContactAddress', 'url' => '/contacts/{bookid}/{uri}', 'verb' => 'DELETE'],
|
||||
['name' => 'contacts#getContactLetterAvatar', 'url' => '/contacts-avatar', 'verb' => 'GET'],
|
||||
|
||||
|
@ -391,7 +391,51 @@ class ContactsController extends Controller {
|
||||
|
||||
}
|
||||
|
||||
private function addressBookIsReadOnly($bookid) {
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function addContactToMap($bookid, $uri, $myMapId, $fileId=null) {
|
||||
$userFolder = $this->root->getUserFolder($this->userId);
|
||||
$folders = $userFolder->getById($myMapId);
|
||||
if (empty($folders)) {
|
||||
return DataResponse('MAP NOT FOUND', 404);
|
||||
}
|
||||
$mapsFolder = array_shift($folders);
|
||||
if (is_null($mapsFolder)) {
|
||||
return DataResponse('MAP NOT FOUND',404);
|
||||
}
|
||||
if (is_null($fileId)) {
|
||||
$card = $this->cdBackend->getContact($bookid, $uri);
|
||||
try {
|
||||
$file=$mapsFolder->get($uri);
|
||||
} catch (NotFoundException $e) {
|
||||
if (!$mapsFolder->isCreatable()) {
|
||||
return DataResponse('CONTACT NOT WRITABLE', 400);
|
||||
}
|
||||
$file=$mapsFolder->newFile($uri);
|
||||
}
|
||||
} else {
|
||||
$files = $mapsFolder->getById($fileId);
|
||||
if (empty($files)) {
|
||||
return DataResponse('CONTACT NOT FOUND', 404);
|
||||
}
|
||||
$file = array_shift($files);
|
||||
if (is_null($file)) {
|
||||
return DataResponse('CONTACT NOT FOUND', 404);
|
||||
}
|
||||
$card = $file->getContent();
|
||||
}
|
||||
if (!$file->isUpdateable()) {
|
||||
return DataResponse('CONTACT NOT WRITABLE', 400);
|
||||
}
|
||||
if ($card) {
|
||||
$vcard = Reader::read($card['carddata']);
|
||||
$file->putContent($vcard->serialize());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function addressBookIsReadOnly($bookid) {
|
||||
$userBooks = $this->cdBackend->getAddressBooksForUser('principals/users/'.$this->userId);
|
||||
foreach ($userBooks as $book) {
|
||||
if ($book['id'] === $bookid) {
|
||||
|
@ -136,6 +136,16 @@ export function placeContact(bookid, uri, uid, lat, lng, address = null, type =
|
||||
return axios.put(url, req)
|
||||
}
|
||||
|
||||
export function addContactToMap(bookid, uri, uid, myMapId, fileId = null) {
|
||||
const req = {
|
||||
uid,
|
||||
fileId,
|
||||
myMapId,
|
||||
}
|
||||
const url = generateUrl('apps/maps/contacts/' + bookid + '/' + uri + '/add-to-map/')
|
||||
return axios.put(url, req)
|
||||
}
|
||||
|
||||
export function getFavorites(myMapId = null) {
|
||||
const conf = {
|
||||
params: {
|
||||
|
@ -200,7 +200,6 @@ import L from 'leaflet'
|
||||
import { geoToLatLng, getFormattedADR } from '../utils/mapUtils'
|
||||
import * as network from '../network'
|
||||
import { all as axiosAll, spread as axiosSpread } from 'axios'
|
||||
import {deleteSharedFavoriteCategoryFromMap} from "../network";
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
@ -989,8 +988,7 @@ export default {
|
||||
},
|
||||
onAddContactToMap(c) {
|
||||
this.chooseMyMap((map) => {
|
||||
const latLng = geoToLatLng(c.GEO)
|
||||
network.placeContact(c.BOOKID, c.URI, c.UID, latLng[0], latLng[1], c.ADR, c.ADRTYPE, c.FILEID, map.id).then((response) => {
|
||||
network.addContactToMap(c.BOOKID, c.URI, c.UID, map.id, c.FILEID).then((response) => {
|
||||
showSuccess(t('maps', 'Contact {contactName} added to map {mapName}', { contactName: c.FN ?? '', mapName: map.name ?? '' }))
|
||||
}).catch((error) => {
|
||||
console.error(error)
|
||||
@ -1001,8 +999,7 @@ export default {
|
||||
onAddAllContactsToMap() {
|
||||
this.chooseMyMap((map) => {
|
||||
axiosAll(this.contacts.map((c) => {
|
||||
const latLng = geoToLatLng(c.GEO)
|
||||
return network.placeContact(c.BOOKID, c.URI, c.UID, latLng[0], latLng[1], c.ADR, c.ADRTYPE, c.FILEID, map.id)
|
||||
return network.addContactToMap(c.BOOKID, c.URI, c.UID, map.id, c.FILEID)
|
||||
})).then(axiosSpread((...responses) => {
|
||||
showSuccess(t('maps', 'All Contacts added to map {mapName}', { mapName: map.name ?? '' }))
|
||||
})).catch((error) => {
|
||||
@ -1035,8 +1032,7 @@ export default {
|
||||
})
|
||||
this.chooseMyMap((map) => {
|
||||
axiosAll(contactsInGroup.map((c) => {
|
||||
const latLng = geoToLatLng(c.GEO)
|
||||
return network.placeContact(c.BOOKID, c.URI, c.UID, latLng[0], latLng[1], c.ADR, c.ADRTYPE, c.FILEID, map.id)
|
||||
return network.addContactToMap(c.BOOKID, c.URI, c.UID, map.id, c.FILEID)
|
||||
})).then(axiosSpread((...responses) => {
|
||||
showSuccess(t('maps', 'All Contacts added to map {mapName}', { mapName: map.name ?? '' }))
|
||||
})).catch((error) => {
|
||||
@ -1456,10 +1452,10 @@ export default {
|
||||
favIds.forEach((favid) => {
|
||||
this.$delete(this.favorites, favid)
|
||||
})
|
||||
showSuccess(t('maps', 'Favorite category {favoriteName} unlinked from map', { favoriteName: catid ?? ''}))
|
||||
showSuccess(t('maps', 'Favorite category {favoriteName} unlinked from map', { favoriteName: catid ?? '' }))
|
||||
}).catch((error) => {
|
||||
console.error(error)
|
||||
showError(t('maps', 'Failed to remove Favorite category {favoriteName} from map', { favoriteName: catid ?? ''}))
|
||||
showError(t('maps', 'Failed to remove Favorite category {favoriteName} from map', { favoriteName: catid ?? '' }))
|
||||
})
|
||||
},
|
||||
onFavoriteAdd(latLng) {
|
||||
|
Reference in New Issue
Block a user