Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
brantje committed Aug 10, 2014
0 parents commit fee6bfc
Show file tree
Hide file tree
Showing 17 changed files with 1,030 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: php
php:
- 5.3
- 5.4
- 5.5

before_install:
- cd ..
- git clone https://github.com/owncloud/core.git
- mv maps core/apps/
- cd core
- git submodule init
- git submodule update
- cd apps/maps

script:
- phpunit tests
4 changes: 4 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Authors

* Sander Brand: <[email protected]>

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
owncloud-maps (0.0.1)
* First release
661 changes: 661 additions & 0 deletions COPYING

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Maps
Place this app in **owncloud/apps/**


## Running tests
After [Installing PHPUnit](http://phpunit.de/getting-started.html) run:

phpunit tests/
33 changes: 33 additions & 0 deletions appinfo/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* ownCloud - maps
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <[email protected]>
* @copyright Sander Brand 2014
*/

namespace OCA\Maps\AppInfo;


\OCP\App::addNavigationEntry(array(
// the string under which your app will be referenced in owncloud
'id' => 'maps',

// sorting weight for the navigation. The higher the number, the higher
// will it be listed in the navigation
'order' => 10,

// the route that will be shown on startup
'href' => \OCP\Util::linkToRoute('maps.page.index'),

// the icon that will be shown in the navigation
// this file needs to exist in img/
'icon' => \OCP\Util::imagePath('maps', 'app.svg'),

// the title of your application. This will be used in the
// navigation or on the settings page of your app
'name' => \OC_L10N::get('maps')->t('Maps')
));
50 changes: 50 additions & 0 deletions appinfo/application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* ownCloud - maps
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <[email protected]>
* @copyright Sander Brand 2014
*/

namespace OCA\Maps\AppInfo;


use \OCP\AppFramework\App;

use \OCA\Maps\Controller\PageController;


class Application extends App {


public function __construct (array $urlParams=array()) {
parent::__construct('maps', $urlParams);

$container = $this->getContainer();

/**
* Controllers
*/
$container->registerService('PageController', function($c) {
return new PageController(
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId')
);
});


/**
* Core
*/
$container->registerService('UserId', function($c) {
return \OCP\User::getUser();
});

}


}
10 changes: 10 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<info>
<id>maps</id>
<name>Maps</name>
<description>A simple maps app</description>
<licence>agpl</licence>
<author>Sander Brand</author>
<version>0.0.1</version>
<requiremin>7</requiremin>
</info>
27 changes: 27 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* ownCloud - maps
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <[email protected]>
* @copyright Sander Brand 2014
*/

namespace OCA\Maps\AppInfo;

/**
* Create your routes in here. The name is the lowercase name of the controller
* without the controller part, the stuff after the hash is the method.
* e.g. page#index -> PageController->index()
*
* The controller class has to be registered in the application.php file since
* it's instantiated in there
*/
$application = new Application();

$application->registerRoutes($this, array('routes' => array(
array('name' => 'page#index', 'url' => '/', 'verb' => 'GET'),
array('name' => 'page#do_echo', 'url' => '/echo', 'verb' => 'POST'),
)));
54 changes: 54 additions & 0 deletions controller/pagecontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* ownCloud - maps
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <[email protected]>
* @copyright Sander Brand 2014
*/

namespace OCA\Maps\Controller;


use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller;

class PageController extends Controller {

private $userId;

public function __construct($appName, IRequest $request, $userId){
parent::__construct($appName, $request);
$this->userId = $userId;
}


/**
* CAUTION: the @Stuff turn off security checks, for this page no admin is
* required and no CSRF check. If you don't know what CSRF is, read
* it up in the docs or you might create a security hole. This is
* basically the only required method to add this exemption, don't
* add it to any other method if you don't exactly know what it does
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index() {
$params = array('user' => $this->userId);
return new TemplateResponse('maps', 'main', $params); // templates/main.php
}


/**
* Simply method that posts back the payload of the request
* @NoAdminRequired
*/
public function doEcho($echo) {
return array('echo' => $echo);
}


}
3 changes: 3 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#hello {
color: red;
}
7 changes: 7 additions & 0 deletions img/app.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* ownCloud - maps
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <[email protected]>
* @copyright Sander Brand 2014
*/

(function ($, OC) {

$(document).ready(function () {
$('#hello').click(function () {
alert('Hello from your script file');
});

$('#echo').click(function () {
var url = OC.generateUrl('/apps/maps/echo');
var data = {
echo: $('#echo-content').val()
};

$.post(url, data).success(function (response) {
$('#echo-result').text(response.echo);
});

});
});

})(jQuery, OC);
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<phpunit bootstrap="tests/autoloader.php"></phpunit>
17 changes: 17 additions & 0 deletions templates/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
\OCP\Util::addScript('maps', 'script');

\OCP\Util::addStyle('maps', 'style');

?>

<p>Hello World <?php p($_['user']) ?></p>

<p><button id="hello">click me</button></p>

<p><textarea id="echo-content">
Send this as ajax
</textarea></p>
<p><button id="echo">Send ajax request</button></p>

Ajax response: <div id="echo-result"></div>
52 changes: 52 additions & 0 deletions tests/autoloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* ownCloud - maps
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <[email protected]>
* @copyright Sander Brand 2014
*/

require_once __DIR__ . '/../../../3rdparty/Pimple/Pimple.php';


class OC {
public static $server;
public static $session;
}

// to execute without owncloud, we need to create our own classloader
spl_autoload_register(function ($className){
if (strpos($className, 'OCA\\') === 0) {

$path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
$relPath = __DIR__ . '/../..' . $path;

if(file_exists($relPath)){
require_once $relPath;
}
} else if(strpos($className, 'OCP\\') === 0) {
$path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
$relPath = __DIR__ . '/../../../lib/public' . $path;

if(file_exists($relPath)){
require_once $relPath;
}
} else if(strpos($className, 'OC_') === 0) {
$path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
$relPath = __DIR__ . '/../../../lib/private/' . $path;

if(file_exists($relPath)){
require_once $relPath;
}
} else if(strpos($className, 'OC\\') === 0) {
$path = strtolower(str_replace('\\', '/', substr($className, 2)) . '.php');
$relPath = __DIR__ . '/../../../lib/private' . $path;

if(file_exists($relPath)){
require_once $relPath;
}
}
});
53 changes: 53 additions & 0 deletions tests/unit/controller/PageControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* ownCloud - maps
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <[email protected]>
* @copyright Sander Brand 2014
*/

namespace OCA\Maps\Controller;


use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Http\JSONResponse;

use \OCA\Maps\AppInfo\Application;


class PageControllerTest extends \PHPUnit_Framework_TestCase {

private $container;

public function setUp () {
$app = new Application();
$this->container = $app->getContainer();
}


public function testIndex () {
// swap out request
$this->container['Request'] = $this->getMockBuilder('\OCP\IRequest')
->getMock();
$this->container['UserId'] = 'john';

$result = $this->container['PageController']->index();

$this->assertEquals(array('user' => 'john'), $result->getParams());
$this->assertEquals('main', $result->getTemplateName());
$this->assertTrue($result instanceof TemplateResponse);
}


public function testEcho () {
$result = $this->container['PageController']->doEcho('hi');

$this->assertEquals(array('echo' => 'hi'), $result);
}


}

0 comments on commit fee6bfc

Please sign in to comment.