1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Version check and news feed messages

This commit is contained in:
Hillel Coren 2014-10-06 00:00:42 +03:00
parent e7184ab59d
commit 70b409184a
20 changed files with 212 additions and 40 deletions

View File

@ -36,20 +36,9 @@ class AccountController extends \BaseController {
public function update()
{
if (!Utils::isNinja()) {
// populate migrations if the application was initially setup using database.sql
$migrations = DB::table('migrations')->get();
if (Schema::hasTable('accounts') && count($migrations) == 0) {
$migrations = ['2013_11_05_180133_confide_setup_users_table', '2013_11_28_195703_setup_countries_table', '2014_02_13_151500_add_cascase_drops', '2014_02_19_151817_add_support_for_invoice_designs', '2014_03_03_155556_add_phone_to_account', '2014_03_19_201454_add_language_support', '2014_03_20_200300_create_payment_libraries', '2014_03_23_051736_enable_forcing_jspdf', '2014_03_25_102200_add_sort_and_recommended_to_gateways', '2014_04_03_191105_add_pro_plan', '2014_04_17_100523_add_remember_token', '2014_04_17_145108_add_custom_fields', '2014_04_23_170909_add_products_settings', '2014_04_29_174315_add_advanced_settings', '2014_05_17_175626_add_quotes', '2014_06_17_131940_add_accepted_credit_cards_to_account_gateways', '2014_07_13_142654_one_click_install', '2014_07_17_205900_support_hiding_quantity', '2014_07_24_171214_add_zapier_support'];
foreach ($migrations as $migration) {
DB::table('migrations')->insert([
'migration' => $migration,
'batch' => 1
]);
}
}
try {
Artisan::call('migrate');
Cache::flush();
} catch (Exception $e) {
Response::make($e->getMessage(), 500);
}

View File

@ -128,6 +128,29 @@ class HomeController extends BaseController {
}
}
public function newsFeed($userType, $version)
{
$response = Utils::getNewsFeedResponse($userType);
return Response::json($response);
}
public function hideMessage()
{
if (Auth::check() && Session::has('news_feed_id')) {
$newsFeedId = Session::get('news_feed_id');
if ($newsFeedId != NEW_VERSION_AVAILABLE && $newsFeedId > Auth::user()->news_feed_id) {
$user = Auth::user();
$user->news_feed_id = $newsFeedId;
$user->save();
}
Session::forget('news_feed_message');
}
return 'success';
}
public function logError()
{
return Utils::logError(Input::get('error'), 'JavaScript');

View File

@ -463,6 +463,9 @@ class UserController extends BaseController {
}
}
Session::forget('news_feed_id');
Session::forget('news_feed_message');
Confide::logout();
return Redirect::to('/')->with('clearGuestKey', true);

View File

@ -0,0 +1,46 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class TrackLastSeenMessage extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function($table)
{
$table->unsignedInteger('news_feed_id')->nullable();
});
if (DB::table('payment_libraries')->count() > 0) {
DB::table('gateways')->update(['recommended' => 0]);
DB::table('gateways')->insert([
'name' => 'moolah',
'provider' => 'AuthorizeNet_AIM',
'sort_order' => 1,
'recommended' => 1,
'site_url' => 'https://invoiceninja.mymoolah.com/',
'payment_library_id' => 1
]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function($table)
{
$table->dropColumn('news_feed_id');
});
}
}

View File

@ -17,13 +17,18 @@ class PaymentLibrariesSeeder extends Seeder
Gateway::create($gateway);
}
Gateway::create([
'name' => 'moolah',
'provider' => 'AuthorizeNet_AIM',
'sort_order' => 1,
'recommended' => 1,
'site_url' => 'https://invoiceninja.mymoolah.com/',
]);
// check that moolah exists
if (!DB::table('gateways')->where('name', '=', 'moolah')->get()) {
DB::table('gateways')->update(['recommended' => 0]);
DB::table('gateways')->insert([
'name' => 'moolah',
'provider' => 'AuthorizeNet_AIM',
'sort_order' => 1,
'recommended' => 1,
'site_url' => 'https://invoiceninja.mymoolah.com/',
'payment_library_id' => 1
]);
}
/*
$updateProviders = array(

View File

@ -13,12 +13,6 @@
App::before(function($request)
{
if (Auth::check())
{
$count = Session::get(SESSION_COUNTER, 0);
Session::put(SESSION_COUNTER, ++$count);
}
if (App::environment() == ENV_PRODUCTION)
{
if (!Request::secure())
@ -27,6 +21,41 @@ App::before(function($request)
}
}
if (Auth::check())
{
$count = Session::get(SESSION_COUNTER, 0);
Session::put(SESSION_COUNTER, ++$count);
// check the application is up to date and for any news feed messages
if (!Utils::startsWith($_SERVER['REQUEST_URI'], '/news_feed') && !Session::has('news_feed_id')) {
$data = false;
if (Utils::isNinja()) {
$data = Utils::getNewsFeedResponse();
} else {
$file = @file_get_contents(NINJA_URL . '/news_feed/' . Utils::getUserType() . '/' . NINJA_VERSION);
$data = @json_decode($file);
}
if ($data) {
if ($data->version != NINJA_VERSION) {
$params = [
'user_version' => NINJA_VERSION,
'latest_version'=> $data->version,
'releases_link' => link_to(RELEASES_URL, 'Invoice Ninja', ['target' => '_blank'])
];
Session::put('news_feed_id', NEW_VERSION_AVAILABLE);
Session::put('news_feed_message', trans('texts.new_version_available', $params));
} else {
Session::put('news_feed_id', $data->id);
if ($data->message && $data->id > Auth::user()->news_feed_id) {
Session::put('news_feed_message', $data->message);
}
}
} else {
Session::put('news_feed_id', true);
}
}
}
if (Input::has('lang'))
{
$locale = Input::get('lang');

View File

@ -422,5 +422,7 @@ return array(
'data_visualizations' => 'Data Visualizations',
'sample_data' => 'Sample data shown',
'hide' => 'Hide',
'new_version_available' => 'A new version of :releases_link is available. You\'re running v:user_version, the latest is v:latest_version',
);

View File

@ -430,6 +430,7 @@ return array(
'data_visualizations' => 'Data Visualizations',
'sample_data' => 'Sample data shown',
'hide' => 'Hide',
'new_version_available' => 'A new version of :releases_link is available. You\'re running v:user_version, the latest is v:latest_version',
);

View File

@ -420,5 +420,7 @@ return array(
'data_visualizations' => 'Data Visualizations',
'sample_data' => 'Sample data shown',
'hide' => 'Hide',
'new_version_available' => 'A new version of :releases_link is available. You\'re running v:user_version, the latest is v:latest_version',
);

View File

@ -422,6 +422,8 @@ return array(
'data_visualizations' => 'Data Visualizations',
'sample_data' => 'Sample data shown',
'hide' => 'Hide',
'new_version_available' => 'A new version of :releases_link is available. You\'re running v:user_version, the latest is v:latest_version',
);

View File

@ -422,5 +422,8 @@ return array(
'data_visualizations' => 'Data Visualizations',
'sample_data' => 'Sample data shown',
'hide' => 'Hide',
'new_version_available' => 'A new version of :releases_link is available. You\'re running v:user_version, the latest is v:latest_version',
);

View File

@ -430,6 +430,8 @@ return array(
'data_visualizations' => 'Data Visualizations',
'sample_data' => 'Sample data shown',
'hide' => 'Hide',
'new_version_available' => 'A new version of :releases_link is available. You\'re running v:user_version, the latest is v:latest_version',
);

View File

@ -430,6 +430,8 @@ return array(
'data_visualizations' => 'Data Visualizations',
'sample_data' => 'Sample data shown',
'hide' => 'Hide',
'new_version_available' => 'A new version of :releases_link is available. You\'re running v:user_version, the latest is v:latest_version',
);

View File

@ -423,6 +423,8 @@ return array(
'data_visualizations' => 'Data Visualizations',
'sample_data' => 'Sample data shown',
'hide' => 'Hide',
'new_version_available' => 'A new version of :releases_link is available. You\'re running v:user_version, the latest is v:latest_version',
);

View File

@ -411,6 +411,8 @@ return array(
'data_visualizations' => 'Data Visualizations',
'sample_data' => 'Sample data shown',
'hide' => 'Hide',
'new_version_available' => 'A new version of :releases_link is available. You\'re running v:user_version, the latest is v:latest_version',
);

View File

@ -37,6 +37,29 @@ class Utils
return Auth::check() && Auth::user()->isPro();
}
public static function getUserType()
{
if (Utils::isNinja()) {
return USER_TYPE_CLOUD_HOST;
} else {
return USER_TYPE_SELF_HOST;
}
}
public static function getNewsFeedResponse($userType = false)
{
if (!$userType) {
$userType = Utils::getUserType();
}
$response = new stdClass;
$response->message = isset($_ENV["{$userType}_MESSAGE"]) ? $_ENV["{$userType}_MESSAGE"] : '';
$response->id = isset($_ENV["{$userType}_ID"]) ? $_ENV["{$userType}_ID"] : '';
$response->version = NINJA_VERSION;
return $response;
}
public static function getProLabel($feature)
{
if (Auth::check()
@ -535,4 +558,15 @@ class Utils
//'X-Rate-Limit-Reset' - The number of seconds left in the current period,
];
}
public static function startsWith($haystack, $needle)
{
return $needle === "" || strpos($haystack, $needle) === 0;
}
public static function endsWith($haystack, $needle)
{
return $needle === "" || substr($haystack, -strlen($needle)) === $needle;
}
}

View File

@ -290,7 +290,11 @@ class Account extends Eloquent
foreach ($client->contacts as $contact)
{
$contact->setVisible(['public_id']);
$contact->setVisible([
'public_id',
'first_name',
'last_name',
'email']);
}
}

View File

@ -36,7 +36,7 @@ Route::post('/contact_submit', 'HomeController@doContactUs');
Route::get('/faq', 'HomeController@showFaq');
Route::get('/features', 'HomeController@showFeatures');
Route::get('/testimonials', 'HomeController@showTestimonials');
Route::get('/compare-online-invoicing', 'HomeController@showCompare');
Route::get('/compare-online-invoicing{sites?}', 'HomeController@showCompare');
Route::get('log_error', 'HomeController@logError');
Route::get('invoice_now', 'HomeController@invoiceNow');
@ -54,7 +54,6 @@ Route::get('claim_license', 'PaymentController@claim_license');
Route::post('signup/validate', 'AccountController@checkEmail');
Route::post('signup/submit', 'AccountController@submitSignup');
// Confide routes
Route::get('login', 'UserController@login');
Route::post('login', 'UserController@do_login');
@ -65,11 +64,15 @@ Route::get('user/reset/{token?}', 'UserController@reset_password');
Route::post('user/reset', 'UserController@do_reset_password');
Route::get('logout', 'UserController@logout');
if (Utils::isNinja()) {
Route::get('/news_feed/{user_type}/{version}/', 'HomeController@newsFeed');
}
Route::group(array('before' => 'auth'), function()
{
Route::get('dashboard', 'DashboardController@index');
Route::get('view_archive/{entity_type}/{visible}', 'AccountController@setTrashVisible');
Route::get('hide_message', 'HomeController@hideMessage');
Route::get('force_inline_pdf', 'UserController@forcePDFJS');
Route::get('api/users', array('as'=>'api.users', 'uses'=>'UserController@getDatatable'));
@ -236,11 +239,16 @@ define('NINJA_ACCOUNT_KEY', 'zg4ylmzDkdkPOT8yoKQw9LTWaoZJx79h');
define('NINJA_GATEWAY_ID', GATEWAY_AUTHORIZE_NET);
define('NINJA_GATEWAY_CONFIG', '{"apiLoginId":"626vWcD5","transactionKey":"4bn26TgL9r4Br4qJ","testMode":"","developerMode":""}');
define('NINJA_URL', 'https://www.invoiceninja.com');
define('NINJA_VERSION', '1.3.3');
define('NINJA_VERSION', '1.4.0');
define('RELEASES_URL', 'https://github.com/hillelcoren/invoice-ninja/releases/');
define('PRO_PLAN_PRICE', 50);
define('LICENSE_PRICE', 30.00);
define('USER_TYPE_SELF_HOST', 'SELF_HOST');
define('USER_TYPE_CLOUD_HOST', 'CLOUD_HOST');
define('NEW_VERSION_AVAILABLE', 'NEW_VERSION_AVAILABLE');
/*
define('GATEWAY_AMAZON', 30);
define('GATEWAY_BLUEPAY', 31);

View File

@ -197,7 +197,14 @@
@endif
@if (Session::has('message'))
<div class="alert alert-info">{{ Session::get('message') }}</div>
<div class="alert alert-info">
{{ Session::get('message') }}
</div>
@elseif (Session::has('news_feed_message'))
<div class="alert alert-info">
{{ Session::get('news_feed_message') }}
<a href="#" onclick="hideMessage()" class="pull-right">{{ trans('texts.hide') }}</a>
</div>
@endif
@if (Session::has('error'))
@ -542,6 +549,12 @@ Want something changed? We're {{ link_to('https://github.com/hillelcoren/invoice
}
@endif
function hideMessage() {
$('.alert-info').fadeOut();
$.get('/hide_message', function(response) {
console.log('Reponse: %s', response);
});
}
$(function() {
$('#search').focus(function(){

View File

@ -106,16 +106,16 @@
client.displayBalance = +client.balance;
client.displayPercent = (+client.paid_to_date / (+client.paid_to_date + +client.balance)).toFixed(2);
var oldestInvoice = _.max(client.invoices, function(invoice) { return calculateInvoiceAge(invoice) });
client.displayAge = oldestInvoice ? calculateInvoiceAge(oldestInvoice) : 0;
})
client.displayAge = oldestInvoice ? calculateInvoiceAge(oldestInvoice) : -1;
});
_.each(invoices, function(invoice) {
invoice.displayName = invoice.invoice_number;
invoice.displayTotal = +invoice.amount;
invoice.displayBalance = +invoice.balance;
invoice.displayPercent = parseInt((+invoice.amount - +invoice.balance) / +invoice.amount);
invoice.displayPercent = (+invoice.amount - +invoice.balance) / +invoice.amount;
invoice.displayAge = calculateInvoiceAge(invoice);
})
});
_.each(products, function(product) {
product.displayName = product.key;
@ -123,7 +123,7 @@
product.displayBalance = product.values.amount - product.values.paid;
product.displayPercent = (product.values.paid / product.values.amount).toFixed(2);
product.displayAge = product.values.age;
})
});
/*
_.each(clients, function(client) {
@ -210,7 +210,7 @@
d3.select("#tooltipTitle").text(truncate(d.displayName, 18));
d3.select("#tooltipTotal").text(formatMoney(d.displayTotal));
d3.select("#tooltipBalance").text(formatMoney(d.displayBalance));
d3.select("#tooltipAge").text(pluralize('? day', parseInt(d.displayAge)));
d3.select("#tooltipAge").text(pluralize('? day', parseInt(Math.max(0, d.displayAge))));
if (groupBy == "products" || !d.public_id) {
d3.select("#tooltip a").classed("hidden", true);
@ -260,7 +260,7 @@
.transition()
.duration(1000)
.style("fill", function(d, i) {
return d.displayAge ? color(d.displayAge) : 'grey';
return d.displayAge == -1 ? 'grey' : color(d.displayAge);
});
selection.exit().remove();
@ -281,7 +281,7 @@
function calculateInvoiceAge(invoice) {
if (!invoice || invoice.invoice_status_id == 5) {
return 0;
return -1;
}
return parseInt((new Date().getTime() - Date.parse(invoice.created_at)) / (1000*60*60*24));