Skip to content

Commit

Permalink
Item13033: use earlyInitPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Nov 4, 2014
1 parent 0e06bfb commit a784e1e
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
46 changes: 46 additions & 0 deletions bin/angular
@@ -0,0 +1,46 @@
#!/usr/bin/env perl
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2011-2014 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. For
# more details read LICENSE in the root of this distribution.
#
# 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.
#
# As per the GPL, removal of this notice is prohibited.

use strict;
use warnings;

use File::Spec;

BEGIN {
if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) {
$Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI';
use CGI::Carp qw(fatalsToBrowser);
$SIG{__DIE__} = \&CGI::Carp::confess;
}
else {
$Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI';
require Carp;
$SIG{__DIE__} = \&Carp::confess;
}
my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__);
my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' );
@INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir;
require $setlib;
$action =~ s/\..*$//; # Remove eventual file extension
$ENV{FOSWIKI_ACTION} = $action;
}

use Foswiki ();
use Foswiki::UI ();
$Foswiki::engine->run();

1;
32 changes: 24 additions & 8 deletions lib/Foswiki/Plugins/AngularPlugin.pm
Expand Up @@ -41,11 +41,11 @@ our $service;

=begin TML
---++ initPlugin($topic, $web, $user) -> $boolean
---++ earlyInit()
=cut

sub initPlugin {
sub earlyInitPlugin {

my $request = Foswiki::Func::getRequestObject();
my $context = Foswiki::Func::getContext();
Expand Down Expand Up @@ -75,28 +75,44 @@ sub initPlugin {

# redirect to angular mode
if (!$context->{angular} && $angular && !defined($skin)) {
my $url = Foswiki::Func::getScriptUrl($session->{webName}, $session->{topicName}, 'angular');
my $url = Foswiki::Func::getScriptUrl(undef, undef, 'angular')."/view/$session->{webName}/$session->{topicName}";
#print STDERR "redirecting $session->{webName}.$session->{topicName} to angular ... $url\n";
Foswiki::Func::redirectCgiQuery(undef, $url);
return 1;
Foswiki::Func::redirectCgiQuery(undef, $url, 1);
return;
}

# enter angular mode
if ($angular) {
$context->{angular} = 1;

# set skin path and switch to a neutral place internally unless there's a "skin" url param
# switch to a neutral place internally unless there's a "skin" url param
unless (defined $skin) {
my $web = $Foswiki::cfg{UsersWebName};
my $topic = "SitePreferences";
my $skin = getSkin();

Foswiki::Func::pushTopicContext($web, $topic);
Foswiki::Func::setPreferencesValue("SKIN", getSkin());

}
}
}

return;
}

=begin TML
---++ initPlugin($topic, $web, $user) -> $boolean
=cut

sub initPlugin {

if (Foswiki::Func::getContext()->{angular}) {
my $skin = getSkin();
#print STDERR "skin=$skin\n";
Foswiki::Func::setPreferencesValue("SKIN", $skin);
}

# get all modules
foreach my $moduleName (sort keys %{$Foswiki::cfg{AngularPlugin}{Modules}}) {
registerModule($moduleName)
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/AngularPlugin/Config.spec
Expand Up @@ -20,7 +20,7 @@ $Foswiki::cfg{JQueryPlugin}{Plugins}{ngAria}{Enabled} = 1;
# **STRING**
$Foswiki::cfg{JQueryPlugin}{Plugins}{ngCookies}{Module} = 'Foswiki::Plugins::AngularPlugin::Cookies';
# **BOOLEAN**
$Foswiki::cfg{JQueryPlugin}{Plugins}{ngCookues}{Enabled} = 1;
$Foswiki::cfg{JQueryPlugin}{Plugins}{ngCookies}{Enabled} = 1;

# **STRING**
$Foswiki::cfg{JQueryPlugin}{Plugins}{ngLoader}{Module} = 'Foswiki::Plugins::AngularPlugin::Loader';
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/AngularPlugin/DEPENDENCIES
@@ -1,2 +1,2 @@
Foswiki::Plugins::JQueryPlugin,>=6.00,perl,Required.

AutoTemplatePlugin,>=3.0,perl,Required.
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/AngularPlugin/MANIFEST
@@ -1,3 +1,4 @@
bin/angular 0755
data/System/AngularPlugin.txt 0644
lib/Foswiki/Plugins/AngularPlugin/Animate.pm 0644
lib/Foswiki/Plugins/AngularPlugin/Aria.pm 0644
Expand Down
3 changes: 3 additions & 0 deletions lib/Foswiki/Plugins/AngularPlugin/Service.pm
Expand Up @@ -34,6 +34,9 @@ sub tmpl {

my $context = $request->param('context') || 'view';
Foswiki::Func::getContext()->{$context} = 1;
if ($context eq "view") {
$session->{request}->action("view");
}

throw Foswiki::Contrib::JsonRpcContrib::Error(404, "Topic does not exist")
unless Foswiki::Func::topicExists($web, $topic);
Expand Down

0 comments on commit a784e1e

Please sign in to comment.