Import vcf from files

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2020-07-07 15:55:07 +02:00
parent 87615fb654
commit aaa23c19c0
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
19 changed files with 155 additions and 34 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 689 B

4
img/contacts.svg Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" version="1.1" viewBox="0 0 32 32">
<path style="block-progression:tb;color:#000000;text-transform:none;text-indent:0" d="m8.24 4.42c-2.2265 0-4.1153 1.6283-4.1153 3.7296 0.0158 0.66417 0.0752 1.4832 0.47155 3.2152v0.0429l0.0429 0.0429c0.12723 0.36445 0.31239 0.57294 0.55728 0.85739 0.24489 0.28444 0.53685 0.61924 0.81448 0.90025 0.0327 0.0331 0.0536 0.0535 0.0857 0.0858 0.0551 0.23961 0.12176 0.49747 0.17147 0.72878 0.13227 0.61541 0.11871 1.0512 0.0857 1.2003-0.95674 0.33594-2.147 0.73601-3.2151 1.2003-0.59962 0.26069-1.1422 0.49348-1.5861 0.77165-0.44388 0.27818-0.88534 0.48834-1.0288 1.1146-0.002 0.0285-0.002 0.0572 0 0.0858-0.1402 1.2874-0.35229 3.1806-0.51441 4.4584-0.035 0.26898 0.10676 0.55252 0.34294 0.68591 1.9392 1.0475 4.9181 1.4691 7.8876 1.4576 2.9695-0.0116 5.9247-0.45797 7.8019-1.4576 0.23617-0.13338 0.37794-0.41693 0.34294-0.68591-0.0518-0.39943-0.11534-1.3001-0.17147-2.1863-0.0561-0.88623-0.10486-1.758-0.17147-2.2721-0.0232-0.12744-0.0835-0.2479-0.17147-0.34295-0.59633-0.71211-1.4873-1.1474-2.5292-1.5862-0.95121-0.40054-2.0664-0.81649-3.1722-1.2861-0.0619-0.13788-0.12337-0.53903 0-1.1575 0.0331-0.16606 0.085-0.34392 0.12861-0.51443 0.10392-0.1164 0.18492-0.21152 0.30007-0.34296 0.2456-0.28032 0.50949-0.57438 0.72875-0.85738 0.21926-0.28301 0.39864-0.52579 0.51441-0.85739l0.0429-0.0429c0.44807-1.8085 0.44831-2.5631 0.47155-3.2152v-0.0429c0-2.1013-1.8888-3.7296-4.1153-3.7296zm11.772-3.4224c-3.2461 0-5.9999 2.3739-5.9999 5.4374 0.023 0.9683 0.10964 2.1624 0.68749 4.6874v0.0625l0.0625 0.0625c0.1855 0.53134 0.45545 0.83529 0.81249 1.25 0.35704 0.4147 0.7827 0.90279 1.1875 1.3125 0.0476 0.0482 0.0781 0.0781 0.12499 0.12502 0.0803 0.34932 0.17752 0.72527 0.25 1.0625 0.19284 0.8972 0.17306 1.5326 0.12501 1.75-1.3949 0.48977-3.1303 1.073-4.6874 1.75-0.87422 0.38005-1.6653 0.71943-2.3125 1.125-0.64717 0.40555-1.2908 0.71195-1.5 1.625-0.003 0.0416-0.003 0.0834 0 0.12502-0.20442 1.8769-0.51363 4.637-0.74999 6.4999-0.051 0.39215 0.15566 0.80553 0.49999 0.99999 2.8273 1.5272 7.1704 2.1419 11.5 2.125 4.3294-0.0168 8.6379-0.66766 11.375-2.125 0.34433-0.19446 0.55102-0.60784 0.49999-0.99999-0.0755-0.58232-0.16816-1.8954-0.25-3.1875-0.0818-1.292-0.15288-2.563-0.24998-3.3125-0.0339-0.18578-0.12172-0.36141-0.25-0.49999-0.86942-1.0382-2.1684-1.6728-3.6875-2.3125-1.3868-0.58395-3.0127-1.1904-4.6249-1.875-0.0902-0.20102-0.17988-0.78586 0-1.6875 0.0483-0.2421 0.12394-0.50141 0.1875-0.74999 0.15152-0.1697 0.26961-0.30838 0.4375-0.5 0.35807-0.40868 0.74281-0.83739 1.0625-1.25 0.31967-0.41259 0.58121-0.76654 0.74999-1.25l0.0625-0.0625c0.65328-2.6366 0.65362-3.7367 0.6875-4.6874v-0.0625c0-3.0635-2.7538-5.4374-5.9999-5.4374z" fill="#FFF"/>
</svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" version="1.1" xml:space="preserve" height="16" width="16" enable-background="new 0 0 595.275 311.111" y="0px" x="0px" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" viewBox="0 0 16 16"><path d="m2.5-0.000002c-1.385 0-2.5 1.115-2.5 2.5v11c0 1.385 1.115 2.5 2.5 2.5h11c1.385 0 2.5-1.115 2.5-2.5v-11c0-1.385-1.115-2.5-2.5-2.5h-11zm7.127 1.5654c1.3996 0 2.5869 1.0229 2.5869 2.3438v0.02734c-0.01461 0.4099-0.01521 0.88469-0.29688 2.0215l-0.02637 0.02637c-0.07277 0.20845-0.18541 0.36117-0.32324 0.53906-0.13784 0.1779-0.3046 0.36286-0.45898 0.53906-0.07239 0.08262-0.12315 0.14265-0.18848 0.21582-0.0274 0.10718-0.06023 0.21886-0.08105 0.32324-0.07756 0.38875-0.03889 0.64087 0 0.72754 0.69512 0.29517 1.3962 0.55682 1.9941 0.80859 0.65497 0.27581 1.215 0.54944 1.5898 0.99707 0.05531 0.05975 0.09378 0.13474 0.1084 0.21484 0.04186 0.32315 0.07215 0.87165 0.10742 1.4287 0.03529 0.5571 0.07585 1.123 0.1084 1.374 0.022 0.16908-0.06736 0.3478-0.21582 0.43164-1.1801 0.62834-3.0376 0.90876-4.9043 0.91602-1.867 0.007-3.7402-0.258-4.9592-0.916-0.1485-0.084-0.2369-0.263-0.2149-0.432 0.0452-0.355 0.0928-0.8 0.1436-1.241-0.015427 0.000115-0.030469 0.0019-0.045898 0.002-1.2803 0.005-2.5643-0.17727-3.4004-0.62891-0.10183-0.05751-0.16353-0.17992-0.14844-0.2959 0.0699-0.55094 0.16123-1.3668 0.22168-1.9219-0.00085-0.01233-0.00085-0.02482 0-0.03711 0.0618-0.2699 0.2529-0.3604 0.4443-0.4803 0.1914-0.12 0.425-0.2206 0.6836-0.333 0.4605-0.2002 0.9732-0.3728 1.3857-0.5176 0.0142-0.0643 0.0209-0.2523-0.0361-0.5176-0.0215-0.0997-0.0505-0.2102-0.0742-0.3135-0.0139-0.0139-0.0231-0.0228-0.0372-0.0371-0.1197-0.1212-0.2459-0.2661-0.3515-0.3887s-0.1854-0.212-0.2403-0.3691l-0.018555-0.01855v-0.01856c-0.17089-0.74677-0.19631-1.1004-0.20312-1.3867 0-0.906 0.81444-1.6074 1.7744-1.6074 0.95998 0 1.7744 0.70143 1.7744 1.6074v0.01855c-0.01002 0.28116-0.00994 0.60697-0.20312 1.3867l-0.018555 0.01855c-0.0498 0.143-0.127 0.2472-0.2216 0.3692-0.0945 0.122-0.2085 0.2493-0.3144 0.3701-0.0497 0.0567-0.0841 0.0973-0.1289 0.1475-0.018801 0.07352-0.041394 0.15008-0.055664 0.22168-0.053192 0.26666-0.02669 0.43958 0 0.49902 0.4768 0.2025 0.9571 0.382 1.3672 0.5547 0.3097 0.1304 0.585 0.263 0.8125 0.4316 0.3071-0.1103 0.6104-0.2163 0.8789-0.3105 0.0207-0.0938 0.0285-0.3671-0.0547-0.7539-0.0312-0.1454-0.0728-0.3074-0.1074-0.458-0.0202-0.0203-0.0332-0.034-0.0537-0.0547-0.1745-0.1767-0.3588-0.3867-0.5127-0.5655-0.154-0.1788-0.2696-0.3099-0.3496-0.539l-0.027343-0.02637v-0.02734c-0.2492-1.0887-0.286-1.604-0.296-2.0215 0-1.3209 1.1873-2.3438 2.5869-2.3438z"/></svg>

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" version="1.1" xml:space="preserve" height="128" width="128" enable-background="new 0 0 595.275 311.111" y="0px" x="0px" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" viewBox="0 0 128 128"><rect rx="20" ry="20" height="128" width="128" y="-.0000015" x="0" fill="#0082c9"/><path style="color:#000000;block-progression:tb;text-transform:none;text-indent:0" fill="#fff" d="m36.408 24.326c-7.6798 0-14.195 5.6165-14.195 12.864 0.0545 2.2909 0.25939 5.116 1.6265 11.09v0.14797l0.14797 0.14797c0.43885 1.2571 1.0775 1.9762 1.9222 2.9574 0.84469 0.98111 1.8517 2.1359 2.8094 3.1052 0.11279 0.11417 0.18488 0.18454 0.2956 0.29595 0.19006 0.82648 0.41998 1.7159 0.59145 2.5138 0.45624 2.1227 0.40946 3.6259 0.2956 4.1402-3.3001 1.1587-7.4056 2.5387-11.09 4.1402-2.0683 0.89919-3.9398 1.7021-5.4709 2.6616-1.5311 0.95952-3.0538 1.6844-3.5486 3.8446-0.0069 0.0983-0.0069 0.1973 0 0.29595-0.48359 4.4406-1.2151 10.971-1.7743 15.378-0.12072 0.92779 0.36824 1.9058 1.1829 2.3659 6.6888 3.6131 16.964 5.0673 27.206 5.0277 10.243-0.04001 20.436-1.5797 26.911-5.0277 0.81462-0.46006 1.3036-1.4381 1.1829-2.3659-0.17867-1.3777-0.39784-4.4844-0.59145-7.5411-0.1935-3.0568-0.36169-6.0638-0.59145-7.8371-0.08002-0.43958-0.28801-0.85508-0.59145-1.1829-2.0569-2.4563-5.1301-3.9577-8.7239-5.4712-3.281-1.3816-7.1276-2.8163-10.942-4.4361-0.21351-0.47558-0.42554-1.8593 0-3.9925 0.11417-0.57279 0.29319-1.1863 0.44361-1.7744 0.35845-0.4015 0.63784-0.72959 1.035-1.183 0.84714-0.9669 1.7574-1.9812 2.5137-2.9573 0.75629-0.97618 1.375-1.8136 1.7743-2.9574l0.14797-0.14797c1.5455-6.238 1.5463-8.8408 1.6265-11.09v-0.14797c0-7.248-6.515-12.864-14.195-12.864zm40.605-11.805c-11.197 0-20.695 8.1882-20.695 18.755 0.07933 3.3399 0.37818 7.4587 2.3713 16.168v0.21558l0.21558 0.21558c0.63984 1.8327 1.571 2.8811 2.8025 4.3116 1.2315 1.4304 2.6997 3.114 4.096 4.5272 0.16418 0.16626 0.26939 0.26939 0.43112 0.43123 0.27698 1.2049 0.61232 2.5017 0.86232 3.6649 0.66516 3.0947 0.59693 5.2864 0.43119 6.0362-4.8114 1.6894-10.797 3.7011-16.168 6.0362-3.0154 1.3109-5.7441 2.4815-7.9764 3.8804s-4.4523 2.4557-5.1739 5.6051c-0.01035 0.14349-0.01035 0.28767 0 0.43123-0.7051 6.4739-1.7716 15.994-2.5869 22.42-0.17591 1.3526 0.53691 2.7785 1.7246 3.4492 9.7521 5.2677 24.733 7.388 39.667 7.3297 14.933-0.058 29.794-2.3029 39.235-7.3297 1.1877-0.67075 1.9006-2.0966 1.7246-3.4492-0.26042-2.0086-0.58003-6.5378-0.86231-10.995-0.28216-4.4565-0.52733-8.8405-0.86225-11.426-0.11693-0.64081-0.41985-1.2466-0.86232-1.7246-2.9989-3.581-7.4794-5.7699-12.719-7.9764-4.7834-2.0142-10.392-4.106-15.953-6.4674-0.31112-0.69337-0.62046-2.7106 0-5.8206 0.1666-0.83507 0.4275-1.7295 0.64674-2.5869 0.52263-0.58534 0.92996-1.0637 1.5091-1.7246 1.2351-1.4096 2.5622-2.8884 3.6649-4.3116 1.1026-1.4231 2.0048-2.644 2.5869-4.3116l0.21558-0.21558c2.2533-9.0944 2.2545-12.889 2.3714-16.168v-0.21558c0-10.567-9.4986-18.755-20.695-18.755z"/></svg>

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" version="1.1" xml:space="preserve" height="32" width="32" enable-background="new 0 0 595.275 311.111" y="0px" x="0px" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" viewBox="0 0 32 32"><rect rx="5" ry="5" height="32" width="32" y="-.0000052588" x="0" fill="#0082c9"/><path style="color:#000000;block-progression:tb;text-transform:none;text-indent:0" fill="#fff" d="m9.102 6.0816c-1.92 0-3.5487 1.4041-3.5487 3.2161 0.01363 0.57273 0.06485 1.279 0.40663 2.7725v0.03699l0.03699 0.03699c0.10971 0.31427 0.26938 0.49406 0.48055 0.73934s0.46294 0.53398 0.70234 0.7763c0.0282 0.02854 0.04622 0.04613 0.0739 0.07399 0.04751 0.20662 0.105 0.42898 0.14786 0.62844 0.11406 0.53068 0.10236 0.90647 0.0739 1.035-0.82501 0.28969-1.8514 0.63468-2.7724 1.035-0.51706 0.2248-0.98494 0.42554-1.3677 0.66541-0.38277 0.23988-0.76344 0.4211-0.88715 0.96114-0.0017 0.02457-0.0017 0.04932 0 0.07399-0.1209 1.1101-0.30379 2.7427-0.44359 3.8446-0.03018 0.23195 0.09206 0.47645 0.29572 0.59147 1.6722 0.90328 4.241 1.2668 6.8016 1.2569 2.5607-0.01 5.109-0.39492 6.7277-1.2569 0.20365-0.11502 0.3259-0.35953 0.29572-0.59147-0.04467-0.34444-0.09946-1.1211-0.14786-1.8853-0.04838-0.76421-0.09042-1.516-0.14786-1.9593-0.02-0.10989-0.072-0.21377-0.14786-0.29573-0.51423-0.61407-1.2825-0.98942-2.181-1.3678-0.82024-0.34539-1.7819-0.70407-2.7354-1.109-0.05338-0.1189-0.10638-0.46482 0-0.99813 0.02854-0.1432 0.0733-0.29657 0.1109-0.4436 0.08961-0.10037 0.15946-0.1824 0.25876-0.29574 0.21178-0.24172 0.43934-0.4953 0.62841-0.73934s0.34376-0.4534 0.44359-0.73934l0.03699-0.03699c0.38638-1.5595 0.38659-2.2102 0.40663-2.7725v-0.03699c0-1.812-1.6287-3.2161-3.5487-3.2161zm10.151-2.9512c-2.7992 0-5.1738 2.0471-5.1738 4.6888 0.01983 0.83498 0.09454 1.8647 0.59284 4.042v0.05389l0.05389 0.0539c0.15996 0.45818 0.39274 0.72029 0.70062 1.0779 0.30788 0.3576 0.67494 0.77849 1.024 1.1318 0.04105 0.04156 0.06735 0.06735 0.10778 0.10781 0.06925 0.30122 0.15308 0.62541 0.21558 0.91621 0.16629 0.77367 0.14923 1.3216 0.1078 1.5091-1.2028 0.42234-2.6993 0.92527-4.042 1.5091-0.75386 0.32772-1.436 0.62038-1.9941 0.97011-0.55807 0.34971-1.1131 0.61393-1.2935 1.4013-0.0026 0.03587-0.0026 0.07192 0 0.10781-0.17628 1.6185-0.44291 3.9986-0.64673 5.605-0.04398 0.33816 0.13423 0.69462 0.43115 0.86231 2.438 1.3169 6.1832 1.847 9.9167 1.8324 3.7333-0.0145 7.4486-0.57574 9.8089-1.8324 0.29692-0.16769 0.47516-0.52415 0.43115-0.86231-0.0651-0.50214-0.14501-1.6344-0.21558-2.7486-0.07054-1.1141-0.13183-2.2101-0.21556-2.8564-0.02923-0.1602-0.10496-0.31165-0.21558-0.43115-0.74972-0.89526-1.8699-1.4425-3.1798-1.9941-1.1959-0.50355-2.5979-1.0265-3.9881-1.6168-0.07778-0.17334-0.15511-0.67766 0-1.4552 0.04165-0.20877 0.10688-0.43238 0.16168-0.64673 0.13066-0.14634 0.23249-0.26592 0.37726-0.43116 0.30877-0.35241 0.64054-0.7221 0.91621-1.0779 0.27566-0.35578 0.50119-0.661 0.64673-1.0779l0.0539-0.05389c0.565-2.2735 0.565-3.2222 0.594-4.042v-0.05389c0-2.6417-2.3747-4.6888-5.1738-4.6888z"/></svg>

Before

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -23,6 +23,8 @@
namespace OCA\Contacts\AppInfo;
use OCA\Contacts\Dav\PatchPlugin;
use OCA\Contacts\Listener\LoadContactsFilesActions;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\App;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\SabrePluginEvent;
@ -53,5 +55,8 @@ class Application extends App {
$server->addPlugin($this->getContainer()->query(PatchPlugin::class));
}
});
// Register files action
$eventDispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadContactsFilesActions::class);
}
}

View File

@ -34,7 +34,6 @@ use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Reader;
class PatchPlugin extends ServerPlugin {

View File

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020, John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Contacts\Listener;
use OCA\Contacts\AppInfo\Application;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;
class LoadContactsFilesActions implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof LoadAdditionalScriptsEvent)) {
return;
}
Util::addStyle(Application::APP_ID, 'icons');
Util::addScript(Application::APP_ID, 'contacts-files-action');
}
}

View File

@ -23,7 +23,7 @@
<template>
<div id="contact-details" class="app-content-details">
<!-- nothing selected or contact not found -->
<EmptyContent v-if="!contact && !loading" icon="icon-contacts-dark">
<EmptyContent v-if="!contact && !loading" icon="icon-contacts">
{{ t('contacts', 'No contact selected') }}
<template #desc>
{{ t('contacts', 'Select a contact on the list to begin') }}
@ -31,7 +31,7 @@
</EmptyContent>
<!-- loading -->
<EmptyContent v-else-if="loading" icon="icon-contacts-dark">
<EmptyContent v-else-if="loading" icon="icon-contacts">
{{ t('contacts', 'Loading contacts …') }}
</EmptyContent>

View File

@ -1,5 +1,5 @@
<template>
<EmptyContent class="processing-screen__wrapper" icon="icon-contacts-dark">
<EmptyContent class="processing-screen__wrapper" icon="icon-contacts">
<slot />
<template #desc>
<div class="processing-screen__progress">

View File

@ -23,7 +23,7 @@
<template>
<div v-if="propModel" class="grid-span-2 property property--without-actions">
<PropertyTitle
icon="icon-contacts-dark"
icon="icon-contacts"
:readable-name="t('contacts', 'Groups')" />
<div class="property__row">

View File

@ -170,6 +170,20 @@ export default {
return this.importState.stage !== 'default'
},
},
async mounted() {
// Direct import check
if (this.$route.name === 'import') {
const path = this.$route.query.file
this.processLocalFile(path)
this.$router.push({
name: 'group',
params: { selectedGroup: t('contacts', 'All contacts') },
})
}
},
methods: {
/**
* Process input type file change
@ -196,6 +210,27 @@ export default {
reader.readAsText(file)
},
async processLocalFile(path) {
try {
// prepare cancel token for axios request
const source = CancelToken.source()
this.cancelRequest = source.cancel
const file = await axios.get(generateRemoteUrl(`dav/files/${getCurrentUser().uid}`) + encodePath(path), {
cancelToken: source.token,
})
this.$store.dispatch('changeStage', 'parsing')
this.$store.dispatch('setAddressbook', this.selectedAddressbook.displayName)
if (file.data) {
await this.$store.dispatch('importContactsIntoAddressbook', { vcf: file.data, addressbook: this.selectedAddressbook })
}
} catch (error) {
console.error('Something wrong happened while processing local file', error)
}
},
toggleModal() {
this.isOpened = !this.isOpened
// cancel any ongoing request if closed
@ -217,22 +252,9 @@ export default {
// unlikely, but let's cancel any previous request
this.cancelRequest()
// prepare cancel token for axios request
const source = CancelToken.source()
this.cancelRequest = source.cancel
// pick and retrieve file
// pick, retrieve & process file
const path = await picker.pick()
const file = await axios.get(generateRemoteUrl(`dav/files/${getCurrentUser().uid}`) + encodePath(path), {
cancelToken: source.token,
})
this.$store.dispatch('changeStage', 'parsing')
this.$store.dispatch('setAddressbook', this.selectedAddressbook.displayName)
if (file.data) {
await this.$store.dispatch('importContactsIntoAddressbook', { vcf: file.data, addressbook: this.selectedAddressbook })
}
await this.processLocalFile(path)
} catch (error) {
console.error('Something wrong happened while picking a file', error)
} finally {

38
src/files_action.js Normal file
View File

@ -0,0 +1,38 @@
/**
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { generateUrl } from '@nextcloud/router'
window.addEventListener('DOMContentLoaded', () => {
if (OCA.Files && OCA.Files.fileActions) {
OCA.Files.fileActions.registerAction({
name: 'contacts_import',
displayName: t('contacts', 'Import'),
mime: 'text/vcard',
permissions: OC.PERMISSION_READ,
iconClass: 'icon-contacts',
actionHandler: function(fileName, context) {
const absPath = `${context.dir === '/' ? '' : context.dir}/${fileName}`
window.location = generateUrl(`/apps/contacts/import?file=${absPath}`)
},
})
}
})

View File

@ -45,6 +45,11 @@ export default new Router({
params: { selectedGroup: t('contacts', 'All contacts') },
},
children: [
{
path: 'import',
name: 'import',
component: Contacts,
},
{
path: ':selectedGroup',
name: 'group',

View File

@ -3,7 +3,7 @@ if (\OCP\Util::isIe()) {
?>
<div id="app-content">
<div class="emptycontent">
<div class="icon-contacts-dark"></div>
<div class="icon-contacts"></div>
<h2><?php p($l->t('Your web browser is out of date')); ?></h2>
<p><?php p($l->t('This application is not compatible with Internet Explorer')); ?></p>
</div>

View File

@ -7,39 +7,49 @@ const appVersion = JSON.stringify(packageJson.version)
module.exports = {
entry: {
<<<<<<< HEAD
adminSettings: path.join(__dirname, 'src', 'adminSettings.js'),
contacts: path.join(__dirname, 'src', 'main.js'),
=======
[appName]: path.join(__dirname, 'src', 'main.js'),
'contacts-files-action': path.join(__dirname, 'src', 'files_action.js'),
>>>>>>> fa9c8847... Import vcf from files
},
output: {
path: path.resolve(__dirname, './js'),
publicPath: '/js/',
<<<<<<< HEAD
chunkFilename: 'chunks/[name]-[hash].js'
=======
filename: '[name].js',
chunkFilename: 'chunks/[name]-[hash].js',
>>>>>>> fa9c8847... Import vcf from files
},
module: {
rules: [
{
test: /\.css$/,
use: ['vue-style-loader', 'css-loader']
use: ['vue-style-loader', 'css-loader'],
},
{
test: /\.scss$/,
use: ['vue-style-loader', 'css-loader', 'sass-loader']
use: ['vue-style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.(js|vue)$/,
use: 'eslint-loader',
exclude: /node_modules/,
enforce: 'pre'
enforce: 'pre',
},
{
test: /\.vue$/,
loader: 'vue-loader',
exclude: /node_modules/
exclude: /node_modules/,
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
exclude: /node_modules/,
}
]
},
@ -47,10 +57,10 @@ module.exports = {
new VueLoaderPlugin(),
new StyleLintPlugin(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.DefinePlugin({ appVersion })
new webpack.DefinePlugin({ appVersion }),
],
resolve: {
extensions: ['*', '.js', '.vue'],
symlinks: false,
}
},
}