ぼちぼちとmetro stryleについて書き綴ろうと思っていたら、WWDC 2013でiOS7の発表があったのでそれに絡めて…と言いますか、iOS7で噂されていた「フラットデザイン」が気になって、Windows 8 のように「影なしのアイコンデザイン」かつ「グリッドシステムに固執したユーザーインターフェース」だったらどうしようか、と心配していたところなのです。本来のフラットデザイン、グリッドシステム、メトロ(地下鉄の標識)のデザインについては、そろそろ Metro Design について考えてみよう – Moonmile Solutions Blog あたりで書き綴っているので、それはさておき。いや、「意匠問題」のところと「コンテンツ主導」のところは関係がありますが、ざっと、1時間ほどで書き下してみたいと思います。
いわゆるホームページ(だっけ?)を眺めると、アイコンがフラットになっているように見えますが、もともとiOS 5,6 のアイコンはデフォルトでグラスよりが掛けられているのと、背景に影がつくようになっているので、iOS 7の処理がそれを外しているだけです。XCode 5 で作れるコントロールも、(おそらくは)XCode 4と同等のもの(下位互換)は用意されるでしょうから、OS が担う標準コントロールの処理が変わった、というところです。なので、いままでのアプリをそのまま iOS 7 に載せれば、「フラットデザイン風」になる可能性は高いかと。そういう意味では、Windows 8 のデザインの追随だったり、既に Android に見られるようなインターフェースがあったり、jQuery UI で作れるような Web サイトのデザインだったりの、寄せ集めな雰囲気は否めません。なので、先駆者としての Mac デザイン?はさておき、ユーザーのニーズに応えました、ってところでしょうか。Microsoft であれ Apple であれ資本主義を元にする会社であるので、本来のデザインの先進さやユーザビリティよりも発売後の一般受けが優先するのでしょう。もちろん、卵と鶏の関係になるので、どちらが先という訳ではないのですが、この「フラットデザイン」に関しては(それが、本来のフラットデザインではないにせよ)、Microsoft よりも Apple のほうが一歩リードしたままのように見えます。
■デザインの歴史は繰り返し、アールデコへ
Windows 8 のメトロデザインが発表された頃から感じていたのが「アールデコ」の匂いです。美術史を紐解けば、アールヌーヴォーの後のアールデコ、アールヌーヴォーがミューシャが代表する(とはいえ、ミューシャ自身はアールヌーヴォーの後期)「ごてごてとした装飾」の時代から一転、機能的なデザインのアールデコへと移ります。流線型を代表とする「機能美」のデザイン感覚ですね。
簡単に言えば、HTTPのURLを指定して、戻り値をXMLやJSONで取得する。XML-PRCの場合は、送るときにXMLデータをPOSTするのだが、RESTの場合はURLを使う。いわゆる ASP.NET MVCのWeb APIと同じ。POSTやPUTなどを使うが、手軽のはPOSTのほう。メソッド名さえ揃えてしまえば、POSTオンリーでもよい気がする。
Role は一般ユーザーということで「Users」としておきます。今回の users テーブルでは Role は自由に設定できるので、想定として「Administrators(管理者)」と「Users(制限ユーザー)」のようなイメージにしておけば ok かと。ブログの場合は「Author」とか「Editor」を使えばわかりやすい。
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is(‘post’)) {
$this->Post->create();
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash(__(‘The post has been saved’));
$this->redirect(array(‘action’ => ‘index’));
} else {
$this->Session->setFlash(__(‘The post could not be saved. Please, try again.’));
}
}
$users = $this->Post->User->find(‘list’);
$this->set(compact(‘users’));
}
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
if (!$this->Post->exists($id)) {
throw new NotFoundException(__(‘Invalid post’));
}
if ($this->request->is(‘post’) || $this->request->is(‘put’)) {
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash(__(‘The post has been saved’));
$this->redirect(array(‘action’ => ‘index’));
} else {
$this->Session->setFlash(__(‘The post could not be saved. Please, try again.’));
}
} else {
$options = array(‘conditions’ => array(‘Post.’ . $this->Post->primaryKey => $id));
$this->request->data = $this->Post->find(‘first’, $options);
}
$users = $this->Post->User->find(‘list’);
$this->set(compact(‘users’));
}
/**
* delete method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function delete($id = null) {
$this->Post->id = $id;
if (!$this->Post->exists()) {
throw new NotFoundException(__(‘Invalid post’));
}
$this->request->onlyAllow(‘post’, ‘delete’);
if ($this->Post->delete()) {
$this->Session->setFlash(__(‘Post deleted’));
$this->redirect(array(‘action’ => ‘index’));
}
$this->Session->setFlash(__(‘Post was not deleted’));
$this->redirect(array(‘action’ => ‘index’));
}
}
[/code]
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is(‘post’)) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__(‘The user has been saved’));
$this->redirect(array(‘action’ => ‘index’));
} else {
$this->Session->setFlash(__(‘The user could not be saved. Please, try again.’));
}
}
}
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
if (!$this->User->exists($id)) {
throw new NotFoundException(__(‘Invalid user’));
}
if ($this->request->is(‘post’) || $this->request->is(‘put’)) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__(‘The user has been saved’));
$this->redirect(array(‘action’ => ‘index’));
} else {
$this->Session->setFlash(__(‘The user could not be saved. Please, try again.’));
}
} else {
$options = array(‘conditions’ => array(‘User.’ . $this->User->primaryKey => $id));
$this->request->data = $this->User->find(‘first’, $options);
}
}
/**
* delete method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function delete($id = null) {
$this->User->id = $id;
if (!$this->User->exists()) {
throw new NotFoundException(__(‘Invalid user’));
}
$this->request->onlyAllow(‘post’, ‘delete’);
if ($this->User->delete()) {
$this->Session->setFlash(__(‘User deleted’));
$this->redirect(array(‘action’ => ‘index’));
}
$this->Session->setFlash(__(‘User was not deleted’));
$this->redirect(array(‘action’ => ‘index’));
}
}
[/code]
以下は、View
□View/Posts/index.ctp
[code lang=”html”]
Paginator->sort(‘id’); ?>
Paginator->sort(‘title’); ?>
Paginator->sort(‘body’); ?>
Paginator->sort(‘created’); ?>
Paginator->sort(‘modified’); ?>
Html->link(__(‘View’), array(‘action’ => ‘view’, $post[‘Post’][‘id’])); ?>
Html->link(__(‘Edit’), array(‘action’ => ‘edit’, $post[‘Post’][‘id’])); ?>
Form->postLink(__(‘Delete’), array(‘action’ => ‘delete’, $post[‘Post’][‘id’]), null, __(‘Are you sure you want to delete # %s?’, $post[‘Post’][‘id’])); ?>
Paginator->counter(array(
‘format’ => __(‘Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}’)
));
?>
Html->link(__(‘View’), array(‘action’ => ‘view’, $user[‘User’][‘id’])); ?>
Html->link(__(‘Edit’), array(‘action’ => ‘edit’, $user[‘User’][‘id’])); ?>
Form->postLink(__(‘Delete’), array(‘action’ => ‘delete’, $user[‘User’][‘id’]), null, __(‘Are you sure you want to delete # %s?’, $user[‘User’][‘id’])); ?>
Paginator->counter(array(
‘format’ => __(‘Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}’)
));
?>
トランザクションを利用する…が、WEB系の場合は、ワンコールのトランザクションしか使えないので、複数のコール/Web APIにまたがる場合は、2フェーズコミットの方法を取る。まあ、チケット予約とかのように普通はダーティコミットの方式がパフォーマンスがよい。最後にチェックを入れて、整合性がなければ/既に予約済みだとかの場合は、エラーにしてしまう方式。社内業務の場合は、それほどパフォーマンスを必要としない or 途中の入力を破棄されるほうが痛い場合は、一時入力を保持する方式でセッションを作る。
ここはワンコールのトランザクションで。
■Model
Model/AppModel.php を書き換え
[code lang=”php”]
class AppModel extends Model {
var $db ;
function begin()
{
$db = ConnectionManager::getDataSource($this->useDbConfig);
$db->begin($this);
}
function commit()
{
$db = ConnectionManager::getDataSource($this->useDbConfig);
$db->commit($this);
}
function rollback()
{
$db = ConnectionManager::getDataSource($this->useDbConfig);
$db->rollback($this);
}
}
[/code]
コネクションが Model に付属するので、$this->useDbConfig も Model 単位になってしまうという罠があるので、多人数で使う場合には考慮が必要。ただ、大抵の場合はワンコネクションで済ませてしまうので、わざわざマルチコネクションを利用してない場合には特に問題にならない。