Skip to content

Commit

Permalink
Merge pull request #26 from Kunstmaan/feature/multiconfig-setup
Browse files Browse the repository at this point in the history
Feature/multiconfig setup
  • Loading branch information
kimausloos committed May 26, 2014
2 parents d66c4b8 + 17f16f5 commit 77437f3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
9 changes: 5 additions & 4 deletions Controller/GoogleAnalyticsAJAXController.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,15 @@ public function saveProfileAction(Request $request) {
*/
public function saveConfigAction(Request $request) {
// get params
$configId = $request->query->get('configId');
$accountId = $request->query->get('accountId');
$propertyId = $request->query->get('propertyId');
$profileId = $request->query->get('profileId');
$disableGoals = $request->query->get('disableGoals');

// edit the config
$em = $this->getDoctrine()->getManager();
$config = $em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->findFirst();
$config = $em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->find($configId);
if ($accountId && $propertyId && $profileId) {
$config->setAccountId($accountId);
$config->setPropertyId($propertyId);
Expand All @@ -192,7 +193,7 @@ public function saveConfigAction(Request $request) {

// set the config name
$configHelper = $this->container->get('kunstmaan_dashboard.helper.google.analytics.config');
$configHelper->init($config->getId());
$configHelper->init($configId);
$profile = $configHelper->getActiveProfile();
$config->setName($profile['profileName']);
$config->setDisableGoals($disableGoals);
Expand Down Expand Up @@ -252,6 +253,7 @@ public function getConfigAction(Request $request) {
* @Route("/segment/add/", name="kunstmaan_dashboard_ajax_segment_add")
*/
public function addSegmentAction(Request $request) {
$configId = $request->query->get('configId');
$em = $this->getDoctrine()->getManager();

// create a new segment
Expand All @@ -262,8 +264,7 @@ public function addSegmentAction(Request $request) {
$segment->setName($name);

// add the segment to the config
$analyticsConfigRepository = $em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig');
$config = $analyticsConfigRepository->findFirst();
$config = $em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->find($configId);
$segment->setConfig($config);
$segments = $config->getSegments();
$segments[] = $segment;
Expand Down
3 changes: 2 additions & 1 deletion Controller/GoogleAnalyticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ public function configAction(Request $request)
$params['accounts'] = $configHelper->getAccounts();
$params['segments'] = $config->getSegments();
$params['disableGoals'] = $config->getDisableGoals();
$params['configId'] = $config->getId();

return $this->render(
'KunstmaanDashboardBundle:GoogleAnalytics:setup.html.twig',
'KunstmaanDashboardBundle:GoogleAnalytics:setupcontainer.html.twig',
$params
);
}
Expand Down
5 changes: 3 additions & 2 deletions Resources/public/js/setup/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ $(function () {
var accountId = $('#account_id').attr('data-id');
var propertyId = $('#property_id').attr('data-id');
var profileId = $('#profile_id').attr('data-id');
var configId = $('#config_id').attr('data-id');


$('#submit_save').click(function() {
Expand All @@ -14,7 +15,7 @@ $(function () {
$.ajax({
type: 'get',
url: url,
data: {'profileId' : profileId, 'propertyId' : propertyId, 'accountId' : accountId, 'disableGoals' : disableGoals},
data: {'profileId' : profileId, 'propertyId' : propertyId, 'accountId' : accountId, 'disableGoals' : disableGoals, 'configId' : configId},
success: function (data) {
// get all new segments
var segments = $('#segments-new').children();
Expand All @@ -36,7 +37,7 @@ $(function () {
$.ajax({
type: 'get',
url: url,
data: {'query' : query, 'name' : name},
data: {'query' : query, 'name' : name, 'configId' : configId},
success: function (data) {
location.reload();
}
Expand Down
10 changes: 7 additions & 3 deletions Resources/views/GoogleAnalytics/setup.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{% extends 'KunstmaanAdminBundle:Default:layout.html.twig' %}

{% block header %}{% endblock %}

{% block content %}
Expand Down Expand Up @@ -61,6 +59,7 @@
<p>
{{ 'dashboard.ga.setup.segment.info' | trans }} <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/segments" target="_blank">{{ 'dashboard.ga.setup.segment.here' | trans }}</a>.
</p>

<ul>
{% for segment in segments %}
<li id="segment-list__{{ segment.id }}">
Expand All @@ -82,7 +81,11 @@
</div>

<div class="setup-group" id="control-group">
<a href="{{ path('kunstmaan_dashboard') }}" class="btn" type="submit">{{ 'dashboard.ga.setup.back' | trans }}</a>
{% if multiconfig is defined %}
<a href="{{ path('GaCollectionsBundle_Index', {'configId':configId}) }}" class="btn" type="submit">{{ 'dashboard.ga.setup.back' | trans }}</a>
{% else %}
<a href="{{ path('kunstmaan_dashboard') }}" class="btn" type="submit">{{ 'dashboard.ga.setup.back' | trans }}</a>
{% endif %}
<button disabled id="submit_save" class="btn btn-primary" type="submit">{{ 'form.save' | trans }}</button>
</div>
</form>
Expand All @@ -97,6 +100,7 @@
<input type="hidden" id="account_id" data-id="{{accountId}}" />
<input type="hidden" id="property_id" data-id="{{propertyId}}" />
<input type="hidden" id="profile_id" data-id="{{profileId}}" />
<input type="hidden" id="config_id" data-id="{{configId}}" />
{% endblock %}

{% block extrajavascript %}
Expand Down
16 changes: 16 additions & 0 deletions Resources/views/GoogleAnalytics/setupcontainer.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'KunstmaanAdminBundle:Default:layout.html.twig' %}

{% block content %}
{% include 'KunstmaanDashboardBundle:GoogleAnalytics:setup.html.twig'
with {
'accountId' : accountId,
'propertyId' : propertyId,
'properties' : properties,
'profileId' : profileId,
'profiles' : profiles,
'accounts' : accounts,
'segments' : segments,
'disableGoals' : disableGoals
}
%}
{% endblock %}

0 comments on commit 77437f3

Please sign in to comment.